Minimum Suffix Flips LeetCode solution in Java
1class Solution {2public int minFlips(String target) {34boolean lastBit = false;56int flips = 0;7for (int i = 0; i < target.length(); i++) {89if (target.charAt(i) == '1' && !lastBit) {10flips++;11lastBit = !lastBit;12} else if (target.charAt(i) == '0' && lastBit) {13flips++;14lastBit = !lastBit;15}16}1718return flips;19}20}