Skip to content

Commit 1fa1b9b

Browse files
authored
Create 1217-minimum-cost-to-move-chips-to-the-same-position.js
1 parent c0f32ef commit 1fa1b9b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {number[]} position
3+
* @return {number}
4+
*/
5+
const minCostToMoveChips = function(position) {
6+
let oddSum = 0, evenSum = 0
7+
for(let i = 0; i < position.length; i++) {
8+
if(position[i] % 2 === 0) evenSum++
9+
else oddSum++
10+
}
11+
return Math.min(oddSum, evenSum)
12+
};

0 commit comments

Comments
 (0)