package leetcode;

/**
 * https://leetcode.com/problems/xor-operation-in-an-array/
 */
public class Problem1486 {
    public int xorOperation(int n, int start) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1486 prob = new Problem1486();
        System.out.println(prob.xorOperation(5, 0)); // 8
        System.out.println(prob.xorOperation(4, 3)); // 8
        System.out.println(prob.xorOperation(1, 7)); // 7
        System.out.println(prob.xorOperation(10, 5)); // 2
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/xor-operation-in-an-array/
 */
public class Problem1486 {
    public int xorOperation(int n, int start) {
        int answer = 0;
        for (int i = 0; i < n; i++) {
            answer ^= start + (2 * i);
        }
        return answer;
    }
}

Solve problem 1486