본문 바로가기

IT/코딩테스트

[Leetcode] 2864. Maximum Odd Binary Number

728x90

https://leetcode.com/problems/maximum-odd-binary-number

class Solution:
    def maximumOddBinaryNumber(self, s: str) -> str:
        count = [0, 0]
        count[0] = s.count('0')
        count[1] = s.count('1')

        s = ''
        for i in range(count[1] - 1):
            s += '1'
        for i in range(count[0]):
            s += '0'
        s += '1'

        return s
728x90