#2864

Maximum Odd Binary Number

newbie · 145 · lc easy +13 · verified · 82.9% accepted · 834 likes · top 94%

Description

A binary string s with at least one '1' is given. Rearrange its bits to form the maximum odd binary number.

Return a string representing that number. Leading zeros in the result are allowed.

Example 1:

Input: s = "010"
Output: "001"
Explanation: Because there is just one '1', it must be in the last position. So the answer is "001".

Example 2:

Input: s = "0101"
Output: "1001"
Explanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is "100". So the answer is "1001".

Code

1
2
3