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 363aadc commit d4bc7daCopy full SHA for d4bc7da
Easy/Distribute Candies.java
@@ -1,15 +1,8 @@
1
class Solution {
2
- public int distributeCandies(int[] candies) {
3
- Map<Integer, Integer> count = new HashMap<>();
4
- int unique = 0;
5
- int n = candies.length;
6
- for (int i=0;i<n;i++) {
7
- if (!count.containsKey(candies[i])) {
8
- unique++;
9
- }
10
- count.put(candies[i],1);
11
12
-
13
- return unique > n/2 ? n/2 : unique;
14
+ public int distributeCandies(int[] candyType) {
+ return Math.min(
+ Arrays.stream(candyType).boxed().collect(Collectors.toSet()).size(),
+ candyType.length / 2
+ );
+ }
15
}
0 commit comments