class Solution { public int minFlipsMonoIncr(String s) { int len = s.length(); int[][] dp = new int[len][2]; if (s.charAt(0) == '0') { dp[0][0] = 0; dp[0][1] = 1; } else { dp[0][1] = 0; dp[0][0] = 1; } for (int i = 1; i < len; i++) { if (s.charAt(i) == '1') { dp[i][1] = Math.min(dp[i-1][0],dp[i-1][1]); dp[i][0] = dp[i-1][0] + 1; }else{ dp[i][1] = Math.min(dp[i-1][0]+1,dp[i-1][1]+1); dp[i][0] = dp[i-1][0]; } } return Math.min(dp[len - 1][1], dp[len - 1][0]); } }