Skip to content

Commit a26e27b

Browse files
authored
Create time-needed-to-rearrange-a-binary-string.cpp
1 parent 907b870 commit a26e27b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// dp
5+
class Solution {
6+
public:
7+
int secondsToRemoveOccurrences(string s) {
8+
int result = 0, cnt = 0;
9+
for (const auto& c : s) {
10+
if (c == '0') {
11+
++cnt;
12+
continue;
13+
}
14+
if (cnt) {
15+
result = max(result + 1, cnt);
16+
}
17+
}
18+
return result;
19+
}
20+
};

0 commit comments

Comments
 (0)