Sum of Unique Elements
EasyP3Coding
Return the sum of all elements of nums that appear exactly once in the array. If there are none, return 0.
Example 1
- Input
- nums = [1,2,3,2]
- Output
- 4
- Why
- 1 and 3 appear once: 1 + 3 = 4.
Example 2
- Input
- nums = [1,1,1,1,1]
- Output
- 0
Example 3
- Input
- nums = [1,2,3,4,5]
- Output
- 15
Constraints
- 0 <= nums.length <= 10^5
- -10^4 <= nums[i] <= 10^4
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.