Find the XOR of Numbers Which Appear Twice - Problem
You are given an array nums, where each number in the array appears either once or twice.
Return the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,3,2]
›
Output:
2
💡 Note:
Only the number 2 appears twice in the array, so we return 2
Example 2 — Multiple Duplicates
$
Input:
nums = [1,2,1,3]
›
Output:
1
💡 Note:
Only the number 1 appears twice, so we return 1
Example 3 — No Duplicates
$
Input:
nums = [1,2,3]
›
Output:
0
💡 Note:
No number appears twice, so we return 0
Constraints
- 1 ≤ nums.length ≤ 50
- 1 ≤ nums[i] ≤ 50
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code