Class Solution

java.lang.Object
g1801_1900.s1871_jump_game_vii.Solution

public class Solution extends Object
1871 - Jump Game VII.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> binary string <code>s</code> and two integers <code>minJump</code> and <code>maxJump</code>. In the beginning, you are standing at index <code>0</code>, which is equal to <code>'0'</code>. You can move from index <code>i</code> to index <code>j</code> if the following conditions are fulfilled:</p> <ul> <li><code>i + minJump <= j <= min(i + maxJump, s.length - 1)</code>, and</li> <li><code>s[j] == '0'</code>.</li> </ul> <p>Return <code>true</code> <em>if you can reach index</em> <code>s.length - 1</code> <em>in</em> <code>s</code><em>, or</em> <code>false</code> <em>otherwise.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;011010&rdquo;, minJump = 2, maxJump = 3</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>In the first step, move from index 0 to index 3.</p> <p>In the second step, move from index 3 to index 5.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;01101110&rdquo;, minJump = 2, maxJump = 3</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= s.length <= 10<sup>5</sup></code></li> <li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li> <li><code>s[0] == '0'</code></li> <li><code>1 <= minJump <= maxJump < s.length</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • canReach

      public boolean canReach(String s, int minJump, int maxJump)