- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1217.java
23 lines (22 loc) · 768 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
packagecom.fishercoder.solutions.secondthousand;
publicclass_1217 {
publicstaticclassSolution1 {
/*
* credit: https://leetcode.com/problems/play-with-chips/discuss/398239/C%2B%2B-3-lines
*/
publicintminCostToMoveChips(int[] position) {
intchipsAtOddPosition = 0;
intchipsAtEvenPosition = 0;
for (inti = 0; i < position.length; i++) {
if (position[i] % 2 == 0) {
chipsAtEvenPosition++;
} else {
chipsAtOddPosition++;
}
}
returnchipsAtEvenPosition > chipsAtOddPosition
? chipsAtOddPosition
: chipsAtEvenPosition;
}
}
}