Skip to content

Commit 5d66332

Browse files
committed
1529. 最少的后缀翻转次数
1 parent 791ad2e commit 5d66332

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.gatsby;
2+
3+
/**
4+
* @author -- gatsby
5+
* @date -- 2022/7/22
6+
* @description -- leetcode 1529 最少的后缀翻转次数
7+
*/
8+
9+
10+
public class _1529MinimumSuffixFlips {
11+
public int minFlips(String target) {
12+
if (target.length() == 0) return 0;
13+
int count = 0;
14+
char base = target.charAt(0);
15+
if (base == '1') count++;
16+
for (int i = 1; i < target.length(); ++i) {
17+
if (target.charAt(i) != base) {
18+
count++;
19+
base = target.charAt(i);
20+
}
21+
}
22+
return count;
23+
}
24+
}

0 commit comments

Comments
 (0)