-
Notifications
You must be signed in to change notification settings - Fork 5
/
DistributeCandies.java
35 lines (29 loc) · 1.08 KB
/
DistributeCandies.java
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
30
31
32
33
34
35
/*
Problem Statement:
Given an integer array with even length, where different numbers in this array represent different kinds of candies.
Each number means one candy of the corresponding kind.
You need to distribute these candies equally in number to brother and sister.
Return the maximum number of kinds of candies the sister could gain
Problem Link:
Distribute Candies: https://leetcode.com/problems/distribute-candies/description/
Solution:
https://github.com/sunnypatel165/leetcode-again/blob/master/solutions/DistributeCandies.java
Author:
Sunny Patel
https://github.com/sunnypatel165
https://www.linkedin.com/in/sunnypatel165/
*/
class Solution {
public int distributeCandies(int[] candies) {
boolean unique[] = new boolean[300010];
int uniqueCount = 0;
for(int i=0;i<candies.length;i++){
if(unique[candies[i]+100000]==false){
uniqueCount++;
unique[candies[i]+100000]=true;
}
}
return Math.min(uniqueCount, candies.length/2);
}
}