Skip to content

Commit 8c8dba7

Browse files
authored
Added Sum of Unique Elements.java
1 parent 4cc2a75 commit 8c8dba7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Easy/Sum of Unique Elements.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.util.Map.Entry;
2+
3+
class Solution {
4+
public int sumOfUnique(int[] nums) {
5+
return Arrays.stream(nums).boxed()
6+
.collect(Collectors.groupingBy(Function.identity(), HashMap::new, Collectors.counting()))
7+
.entrySet().stream().filter(e -> e.getValue().equals(1L)).map(
8+
Entry::getKey).reduce(0, Integer::sum);
9+
}
10+
}

0 commit comments

Comments
 (0)