Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 408 Bytes

1758. Minimum Changes To Make Alternating Binary String.md

File metadata and controls

17 lines (13 loc) · 408 Bytes

Code for " 1758. Minimum Changes To Make Alternating Binary String " (Java)


class Solution {
  public int minOperations(String s) {
    int cost10 = 0; // the cost to make s "1010"

    for (int i = 0; i < s.length(); ++i)
      if (s.charAt(i) - '0' == i % 2)
        ++cost10;

    final int cost01 = s.length() - cost10; // the cost to make s "0101"
    return Math.min(cost10, cost01);
  }
}