2864. Maximum Odd Binary Number
On This Page
class Solution:
def maximumOddBinaryNumber(self, s: str) -> str:
ones = []
zeros = []
for c in s:
if c == '0':
zeros.append(c)
else:
ones.append(c)
zeros = ''.join(zeros)
ones = ''.join(ones)
if len(ones) > 1:
res = ones[1:] + zeros + '1'
return res
return zeros + ones
class Solution:
def maximumOddBinaryNumber(self, s: str) -> str:
cnt = s.count("1")
return "1" * (cnt - 1) + (len(s) - cnt) * "0" + "1"