leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2864.cpp (366B)


      1 class Solution {
      2   public:
      3     string maximumOddBinaryNumber(const string &s) const {
      4         const int n = size(s);
      5         string res(n, '0');
      6         int cnt = 0;
      7         for (int i = 0; i < n; i++) {
      8             if (s[i] == '1') res[cnt++] = '1';
      9         }
     10         if (cnt == n) return s;
     11         res[--cnt] = '0', res.back() = '1';
     12         return res;
     13     }
     14 };