leetcode

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

1404.cpp (268B)


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