Skip to content

Commit d40c4a4

Browse files
committed
Time: 41 ms (39.01%) | Memory: 16.6 MB (75.75%) - LeetSync
1 parent ee30620 commit d40c4a4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def maximumOddBinaryNumber(self, s: str) -> str:
3+
arr = [ch for ch in s]
4+
N = len(s)
5+
l = 0
6+
r = N - 1
7+
while r >= l:
8+
if arr[l] == '1':
9+
l += 1
10+
if arr[r] == '0':
11+
r -= 1
12+
if r >= l and arr[l] == '0' and arr[r] == '1':
13+
arr[l] = '1'
14+
arr[r] = '0'
15+
16+
arr[l-1] = '0'
17+
arr[N - 1] = '1'
18+
19+
return "".join(arr)
20+

0 commit comments

Comments
 (0)