Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SuryaPratapK/052f61358cc562cb14fd479728ec8826 to your computer and use it in GitHub Desktop.
Save SuryaPratapK/052f61358cc562cb14fd479728ec8826 to your computer and use it in GitHub Desktop.
class Solution {
public:
string maximumOddBinaryNumber(string s) {
int count = 0;
int n = s.size();
for(int i=0;i<n;++i){
if(s[i]=='1'){
count++;
s[i]='0'; //Reset value to 0
}
}
//Remake the largest odd string
s[n-1] = '1';
count--;
for(int i=0;i<n-1 and count>0;++i){
s[i]='1';
count--;
}
return s;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment