首页 > 热点 > > >正文

2023-04-09 09:02:30 来源:   哔哩哔哩

【新要闻】LeetCode1871. Jump Game VII

You are given a 0-indexed binary string sand two integers minJumpand maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index ito index jif the following conditions are fulfilled:

i + minJump <= j <= min(i + maxJump, s.length - 1), and


(资料图)

s[j] == '0'.

Return trueif you can reach index s.length - 1in s, or falseotherwise.

Example 1:

Input: s = "011010", minJump = 2, maxJump = 3

Output: trueExplanation: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

能过就不奢求了,用dp,只要在i-maxJump 到i-minJump中有一个是true,那么就一定能跳到i,所以dp[i]就一定是true,这里要break一下,不然又要TLE了。。。

Runtime: 2804 ms, faster than 5.06% of Java online submissions for Jump Game VII.

Memory Usage: 43 MB, less than 85.63% of Java online submissions for Jump Game VII.

标签:

热门话题
精彩推荐
今日推荐
花木