Skip to content

Commit 2ce4109

Browse files
authored
Create 2864. Maximum Odd Binary Number
1 parent 24593e7 commit 2ce4109

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

2864. Maximum Odd Binary Number

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
string maximumOddBinaryNumber(string s) {
4+
vector<char>ans(s.size() ,'0');
5+
int j=0;
6+
for(int i=0;i<s.length() ; i++){
7+
if(s[i]== '1'){
8+
ans[j++]=s[i];
9+
}
10+
}
11+
string sol="";
12+
swap(ans[j-1],ans[s.size()-1]);
13+
for(auto x :ans){
14+
sol+=x;
15+
}
16+
return sol;
17+
}
18+
};

0 commit comments

Comments
 (0)