Package g1801_1900.s1871_jump_game_vii
Class Solution
- java.lang.Object
-
- g1801_1900.s1871_jump_game_vii.Solution
-
public class Solution extends Object
1871 - Jump Game VII.Medium
You are given a 0-indexed binary string
s
and two integersminJump
andmaxJump
. In the beginning, you are standing at index0
, which is equal to'0'
. You can move from indexi
to indexj
if the following conditions are fulfilled:i + minJump <= j <= min(i + maxJump, s.length - 1)
, ands[j] == '0'
.
Return
true
if you can reach indexs.length - 1
ins
, orfalse
otherwise.Example 1:
Input: s = “011010”, minJump = 2, maxJump = 3
Output: true
Explanation:
In the first step, move from index 0 to index 3.
In the second step, move from index 3 to index 5.
Example 2:
Input: s = “01101110”, minJump = 2, maxJump = 3
Output: false
Constraints:
2 <= s.length <= 105
s[i]
is either'0'
or'1'
.s[0] == '0'
1 <= minJump <= maxJump < s.length
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
-
-
Method Detail
-
canReach
public boolean canReach(String s, int minJump, int maxJump)
-
-