Skip to content

Commit 681e73b

Browse files
committed
Runtime: 128 ms (Top 57.69%) | Memory: 15.4 MB (Top 69.23%)
1 parent 102e9ba commit 681e73b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# Runtime: 128 ms (Top 57.69%) | Memory: 15.4 MB (Top 69.23%)
12
class Solution:
23
def maximumBinaryString(self, binary: str) -> str:
3-
zero = binary.count('0') # count number of '0'
4-
zero_idx = binary.index('0') if zero > 0 else 0 # find the index of fist '0' if exists
5-
one = len(binary) - zero_idx - zero # count number of '1' (not including leading '1's)
6-
return f"{binary[:zero_idx]}{'1'*(zero-1)}{'0'*min(zero, 1)}{'1'*one}"
4+
zero = binary.count('0') # count number of '0'
5+
zero_idx = binary.index('0') if zero > 0 else 0 # find the index of fist '0' if exists
6+
one = len(binary) - zero_idx - zero # count number of '1' (not including leading '1's)
7+
return f"{binary[:zero_idx]}{'1'*(zero-1)}{'0'*min(zero, 1)}{'1'*one}"

0 commit comments

Comments
 (0)