Leetcode Problem 2864. Maximum Odd Binary Number

2864. Maximum Odd Binary Number

Leetcode Solutions

Count and Rearrange

  1. Count the number of '1's in the binary string.
  2. Initialize an empty result string.
  3. Append '1's to the result string, one less than the total count of '1's.
  4. Append '0's to the result string, equal to the total count of '0's in the original string.
  5. Append the final '1' to ensure the binary number is odd.
  6. Return the result string.
UML Thumbnail

In-place Rearrangement

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...