Created
March 2, 2024 12:24
-
-
Save SuryaPratapK/052f61358cc562cb14fd479728ec8826 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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