Skip to content

Commit de2351a

Browse files
authored
Create Maximum Odd Binary Number.java
1 parent 5c7f8b7 commit de2351a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Easy/Maximum Odd Binary Number.java

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public String maximumOddBinaryNumber(String s) {
3+
int oneCount = 0;
4+
for (char c : s.toCharArray()) {
5+
oneCount += c == '1' ? 1 : 0;
6+
}
7+
if (oneCount == 0) {
8+
return s;
9+
}
10+
int zeroCount = s.length() - oneCount;
11+
return "1".repeat(oneCount - 1) + "0".repeat(zeroCount) + "1";
12+
}
13+
}

0 commit comments

Comments
 (0)