# Code language: Python classSolution: defminCostToMoveChips(self, position: List[int]) -> int: returnmin(sum(p % 2 == i for p in position) for i in (0, 1))
// Code language: C++ classSolution { public: intminCostToMoveChips(vector<int>& position){ int a = 0, b = 0; for (int p: position) { if (p % 2 == 0) ++a; else ++b; } returnmin(a, b); } };
1 2 3 4 5 6 7 8 9 10 11 12
/** Code language: JavaScript * @param {number[]} position * @return {number} */ var minCostToMoveChips = function(position) { var a = 0, b = 0; for (let i = 0, n = position.length; i < n; ++i) { if (position[i] % 2 == 0) ++a; else ++b; } return a > b ? b : a; };
1 2 3 4 5 6 7 8 9
// Code language: C intminCostToMoveChips(int* position, int positionSize){ int a = 0, b = 0; for (int i = 0; i < positionSize; ++i) { if (position[i] % 2 == 0) ++a; else ++b; } return a > b ? b : a; }