Advertisement
nikunjsoni

1871

May 24th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool canReach(string s, int minJ, int maxJ) {
  4.         int n = s.size(), pre = 0;
  5.         vector<bool> dp(n, false);
  6.         dp[0] = true;
  7.         for (int i = 1; i < n; ++i) {
  8.             if (i >= minJ)
  9.                 pre += dp[i - minJ];
  10.             if (i > maxJ)
  11.                 pre -= dp[i - maxJ - 1];
  12.             dp[i] = pre > 0 && s[i] == '0';
  13.         }
  14.         return dp[n - 1];
  15.     }
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement