Given a non-empty list of integers where every element appears exactly twice except for one element which appears exactly once, find and return that unique element. Your solution should not use extra memory proportional to the input size.

Examples:

Input: nums = [2, 2, 1] Output: 1 Explanation: 1 appears once, 2 appears twice Input: nums = [4, 1, 2, 1, 2] Output: 4 Explanation: 4 appears once, 1 and 2 each appear twice Input: nums = [1] Output: 1 Explanation: Only one element, it is the single number Input: nums = [3, 3, 7, 7, 5] Output: 5 Explanation: 5 appears once, 3 and 7 each appear twice Input: nums = [0, 1, 0] Output: 1 Explanation: 1 appears once, 0 appears twice
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay June 2026

Contest runs June 1 - 30. Complete challenges to climb the leaderboard!

Only the 30 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In