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!

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 September 2026 (Sep 16–30)Sponsored by FLXBL

Contest runs September 16 - 30. Complete challenges to climb the leaderboard!

1st & 2nd: Salesforce certification exam voucher see all prizes

Only the 15 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