-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
33 lines (29 loc) · 777 Bytes
/
Copy pathSolution.java
File metadata and controls
33 lines (29 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public static String maximumOddBinaryNumber(String s) {
int len = s.length();
int count = 0;
for(char c : s.toCharArray()) {
if(c == '1'){
count++;
}
}
StringBuilder res = new StringBuilder();
if(count >= 1){
count--;
for(int i = 0; i < len - 1; i++) {
if(i < count){
res.append('1');
}
else{
res.append('0');
}
}
res.append('1');
}
return res.toString();
}
public static void main(String[] args) {
String s = "0101";
System.out.println(maximumOddBinaryNumber(s));
}
}