leetcode-1529. 灯泡开关 IV

原始思路

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public int minFlips(String target) {
int count = 0;
int n = target.length();
char[] chars = new char[n];
Arrays.fill(chars,'0');
for (int i = 0; i < n; i++) {
char ch = chars[i];
if ((count & 1) == 1) {
if (ch == '0'){
ch = '1';
}else {
ch = '0';
}
}

if (ch != target.charAt(i)) {
// 需要反转
count++;
}
}
return count;
}
}