commit 243edc5f68c4685328e72ebcc3249cb2848a5faf parent 4ba3bdeecd77fe3b1eb3353cb5107d9b94e982e4 Author: AndrewLockVI <andrewlaack1@gmail.com> Date: Thu, 29 Feb 2024 22:20:49 -0600 Completed max odd binary number again Diffstat:
| A | maximum-odd-binary-number/maximum-odd-binary-numberV2.py | | | 18 | ++++++++++++++++++ |
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git a/maximum-odd-binary-number/maximum-odd-binary-numberV2.py b/maximum-odd-binary-number/maximum-odd-binary-numberV2.py @@ -0,0 +1,18 @@ + +#This is the right way. Kinda wasn't thinking that the last +#bit being a one means the number is odd and that is the only +#way.... + +#30ms 93.00% +#16.56MB 75.75% +class Solution: + + def maximumOddBinaryNumber(self, s: str) -> str: + ones = s.count("1") + strReturn = "" + for i in range(ones - 1): + strReturn += "1" + for i in range(len(s) - ones): + strReturn += "0" + strReturn += "1" + return strReturn