Skip to content

Latest commit

 

History

History
25 lines (21 loc) · 594 Bytes

File metadata and controls

25 lines (21 loc) · 594 Bytes

LeetCode Records - Question 1217 Minimum Cost to Move Chips to The Same Position

Attempt 1: Get the odd and even position counts

class Solution {
    public int minCostToMoveChips(int[] position) {
        int oddCounts = 0;
        int evenCounts = 0;

        for (int pos : position) {
            if (pos % 2 == 1) {
                oddCounts++;
            } else {
                evenCounts++;
            }
        }

        return Math.min(oddCounts, evenCounts);
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 40.76 MB (Beats: 89.44%)