Sum of Unique Elements
EasyArray
Description
Given an integer array nums, return the sum of all the unique elements of nums. An element is unique if it appears exactly once.
Examples
Input:
nums = [1,2,3,2]Output:
4Explanation:
2 appears twice, so only 1 and 3 are unique. Sum = 1 + 3 = 4.
Input:
nums = [1,2,3,4,5]Output:
15Explanation:
All elements appear exactly once, so sum all: 1+2+3+4+5 = 15.
Input:
nums = [1,1,1,1]Output:
0Explanation:
No unique elements since 1 appears 4 times. Sum = 0.
Constraints
- •
1 ≤ nums.length ≤ 100 - •
-100 ≤ nums[i] ≤ 100
Ready to solve this problem?
Practice solo and sharpen your skills for technical interviews.