1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class Solution { public int minCostToMoveChips(int[] position) { int odd = 0, even = 0;
for (int index : position) { if ((index & 1) == 1) { odd++; } else { even++; } }
return Math.min(odd, even); } }
|
References
1217. Minimum Cost to Move Chips to The Same Position