Single Number

Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.

Topic refresher: Arrays — Index Thinking

Treat every array problem as: What do I know at index i? What must I remember from the past?

// Running best pattern
int best = nums[0];
for (int i = 1; i < n; i++) {
    // update state using nums[i]
    best = max(best, candidate);
}
return best;
Arrays

Single Number

Easy
LeetCode
9/14
EasyArraysLeetCode #136

Single Number

Every element appears twice except one. Find it in O(n) time O(1) space.

The move

XOR cancels pairs: a^a=0, a^0=a.

Examples

Example 1

Input

3
2 2 1

Output

1
Example 2

Input

5
4 1 2 1 2

Output

4

Stuck? Take a nudge

C++17