--- title: 1529. Minimum Suffix Flips tags: String description: share source code. --- # 1529. Minimum Suffix Flips ```java class Solution { public int minFlips(String target) { char start [] = new char [target.length()]; Arrays.fill(start, '0'); // 重第一個開始翻 return helper(new String(start), target, 0, 0); } public int helper(String start, String target, int idx, int cnt){ if(idx >= start.length()){ return 0; } // 如果翻的次數是奇數才在改變數字 char ch = start.charAt(idx); if(cnt % 2 == 1){ ch = ch == '0' ? '1' :'0'; } int ret = 0; if( ch != target.charAt(idx)){ ret += helper(start, target, idx + 1, cnt + 1) + 1; }else{ ret += helper(start, target, idx + 1, cnt); } return ret; } }