We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4cc2a75 commit 8c8dba7Copy full SHA for 8c8dba7
Easy/Sum of Unique Elements.java
@@ -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