File tree 1 file changed +5
-4
lines changed
scripts/algorithms/M/Maximum Binary String After Change
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change
1
+ # Runtime: 128 ms (Top 57.69%) | Memory: 15.4 MB (Top 69.23%)
1
2
class Solution :
2
3
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 } "
You can’t perform that action at this time.
0 commit comments