leetcode

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

1016.cpp (488B)


      1 class Solution {
      2   public:
      3     bool queryString(const string &s, int n) {
      4         vector<bool> seen(n);
      5         int count = 0;
      6         for (int i = 0; i < size(s) && count < n; i++) {
      7             if (s[i] == '0') continue;
      8             for (int j = 0, crnt = 0; j < 30 && i + j < size(s) && crnt < n; j++) {
      9                 crnt = (crnt << 1) + (s[i + j] & 1);
     10                 if (crnt <= n && !seen[crnt]) seen[crnt] = ++count;
     11             }
     12         }
     13         return count == n;
     14     }
     15 };