-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
1217.java
32 lines (32 loc) · 976 Bytes
/
1217.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
__________________________________________________________________________________________________
0ms
class Solution {
public int minCostToMoveChips(int[] chips) {
if(chips.length == 0) {
return 0;
}
int even = 0, odd = 0;
for (int c : chips) {
if (c % 2 == 1) {
even++;
} else {
odd++;
}
}
return Math.min(even, odd);
}
}
__________________________________________________________________________________________________
sample 2 ms submission
class Solution {
public int minCostToMoveChips(int[] chips) {
int ans = 200;
for(int target : chips) {
int temp = 0;
for(int num : chips) temp += Math.abs(num - target) % 2;
ans = Math.min(ans, temp);
}
return ans;
}
}
__________________________________________________________________________________________________