You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array. Return the sum of all the unique elements of nums.
You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array. Return the sum of all the unique elements of nums.
Example 1:
Input: {"nums":[1,2,3,2]}
Output: 4
Constraints:
1≤nums.length≤100
1≤nums[i]≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,2,3,2]}
Two passes: first tally how many times each value appears, then add up only the values whose tally is exactly 1.
pass 1: tally
pass 2: sum the singles
nums
1
2
3
2
count[x] tally (distinct values in order of first sight)