leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1016.cpp (488B)
0 class Solution {
1 public:
2 bool queryString(const string &s, int n) {
3 vector<bool> seen(n);
4 int count = 0;
5 for (int i = 0; i < size(s) && count < n; i++) {
6 if (s[i] == '0') continue;
7 for (int j = 0, crnt = 0; j < 30 && i + j < size(s) && crnt < n; j++) {
8 crnt = (crnt << 1) + (s[i + j] & 1);
9 if (crnt <= n && !seen[crnt]) seen[crnt] = ++count;
10 }
11 }
12 return count == n;
13 }
14 };