leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2864.cpp (366B)
0 class Solution {
1 public:
2 string maximumOddBinaryNumber(const string &s) const {
3 const int n = size(s);
4 string res(n, '0');
5 int cnt = 0;
6 for (int i = 0; i < n; i++) {
7 if (s[i] == '1') res[cnt++] = '1';
8 }
9 if (cnt == n) return s;
10 res[--cnt] = '0', res.back() = '1';
11 return res;
12 }
13 };