We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 166295f commit 4b8f753Copy full SHA for 4b8f753
2864-maximum-odd-binary-number/2864-maximum-odd-binary-number.py
@@ -1,9 +1,9 @@
1
-from collections import Counter
2
-
3
+# time complexity: O(n)
+# space complexity: O(n)
4
class Solution:
5
def maximumOddBinaryNumber(self, s: str) -> str:
6
- return '1' * (s.count('1') - 1) + '0' * (len(s) - s.count('1')) + '1'
+ oneFreq = s.count('1')
+ return '1' * (oneFreq - 1) + '0' * (len(s) - oneFreq) + '1'
7
8
9
s = "010"
0 commit comments