Skip to content

Latest commit

 

History

History
26 lines (23 loc) · 619 Bytes

xor-operation-in-an-array.md

File metadata and controls

26 lines (23 loc) · 619 Bytes
/**
   Problem Name : XOR Operation in an Array
   Problem URL : https://leetcode.com/problems/xor-operation-in-an-array/
   Description :
    Given an integer n and an integer start.
    Define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length.
    Return the bitwise XOR of all elements of nums.
   Difficulty : Easy
   Language : C#
   Category : Algorithms
*/
public class Solution 
{
    public int XorOperation(int n, int start) 
    {
        int xor = start;
        for(int i = 1; i < n; i++)
            xor ^= (start + (i << 1));
            
        return xor;
    }
}