- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution575.java
More file actions
Latest commit
executable file
·29 lines (25 loc) · 694 Bytes
/
Copy pathSolution575.java
File metadata and controls
executable file
·29 lines (25 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
importjava.util.Arrays;
importjava.util.HashSet;
/**
* Created by slade on 2019/8/12.
*/
publicclassSolution575 {
publicintdistributeCandies(int[] candies) {
HashSethashSet = newHashSet();
for (inti = 0; i < candies.length; i++) {
hashSet.add(candies[i]);
}
intlength0 = candies.length/2;
intlength1 = hashSet.size();
if (length0>length1){
returnlength1;
}else {
returnlength0;
}
}
publicstaticvoidmain(String[] args) {
Solution575s = newSolution575();
int[] candy = {1,1,2,3};
System.out.println(s.distributeCandies(candy));
}
}