Given a list of integers, return the sum of the elements that appear exactly once in the list. Return 0 for null or empty input.
Examples:
Input: nums = [1, 2, 3, 2]
Output: 4
Explanation: 1 and 3 each appear once (1 + 3 = 4), 2 appears twice and is excluded
Input: nums = [1, 1, 1, 1]
Output: 0
Explanation: The only distinct value appears four times, so no unique elements exist
Input: nums = [1, 2, 3, 4, 5]
Output: 15
Explanation: Every element appears exactly once, so the sum is 1+2+3+4+5
Input: nums = []
Output: 0
Explanation: Empty list returns 0
Input: nums = null
Output: 0
Explanation: Null input returns 0
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!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.