Class Solution
java.lang.Object
g1401_1500.s1486_xor_operation_in_an_array.Solution
1486 - XOR Operation in an Array.<p>Easy</p>
<p>You are given an integer <code>n</code> and an integer <code>start</code>.</p>
<p>Define an array <code>nums</code> where <code>nums[i] = start + 2 * i</code> ( <strong>0-indexed</strong> ) and <code>n == nums.length</code>.</p>
<p>Return <em>the bitwise XOR of all elements of</em> <code>nums</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 5, start = 0</p>
<p><strong>Output:</strong> 8</p>
<p><strong>Explanation:</strong> Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8. Where “^” corresponds to bitwise XOR operator.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 4, start = 3</p>
<p><strong>Output:</strong> 8</p>
<p><strong>Explanation:</strong> Array nums is equal to [3, 5, 7, 9] where (3 ^ 5 ^ 7 ^ 9) = 8.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 1000</code></li>
<li><code>0 <= start <= 1000</code></li>
<li><code>n == nums.length</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
xorOperation
public int xorOperation(int n, int start)
-