leetcode

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

1017.cpp (261B)


      1 class Solution {
      2   public:
      3     string baseNeg2(int n) {
      4         if (n == 0) return "0";
      5         string res;
      6         do {
      7             res += to_string(n & 1);
      8         } while ((n = -(n >> 1)));
      9         reverse(begin(res), end(res));
     10         return res;
     11     }
     12 };