문제풀이 2021 02 23
2021.02.23 연습
- 사용언어 : java
class Solution {
public int sumOfUnique(int[] nums) {
Map<Integer, Integer> map = new HashMap<>();
int sum = 0;
for (int i : nums) {
map.put(i, map.getOrDefault(i, 0) + 1);
}
for (int i : nums) {
if (map.get(i) == 1) {
sum += i;
}
}
return sum;
}
}
Runtime: 1 ms, faster than 75.41% of Java online submissions for Sum of Unique Elements. Memory Usage: 36.8 MB, less than 57.73% of Java online submissions for Sum of Unique Elements.