File tree 3 files changed +82
-0
lines changed
solution/1800-1899/1871.Jump Game VII
3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,35 @@ class Solution {
102
102
}
103
103
```
104
104
105
+ ### ** JavaScript**
106
+
107
+ ``` js
108
+ /**
109
+ * @param {string} s
110
+ * @param {number} minJump
111
+ * @param {number} maxJump
112
+ * @return {boolean}
113
+ */
114
+ var canReach = function (s , minJump , maxJump ) {
115
+ let n = s .length ;
116
+ let dp = new Array (n).fill (0 );
117
+ let sum = new Array (n + 1 ).fill (0 );
118
+ dp[0 ] = 1 ;
119
+ sum[1 ] = 1 ;
120
+ for (let i = 1 ; i < n; i++ ) {
121
+ if (s .charAt (i) == ' 0' ) {
122
+ let left = Math .max (0 , i - maxJump);
123
+ let right = i - minJump;
124
+ if (left <= right && sum[right + 1 ] - sum[left] > 0 ) {
125
+ dp[i] = 1 ;
126
+ }
127
+ }
128
+ sum[i + 1 ] = sum[i] + dp[i];
129
+ }
130
+ return dp .pop ();
131
+ };
132
+ ```
133
+
105
134
### ** ...**
106
135
107
136
```
Original file line number Diff line number Diff line change @@ -90,6 +90,35 @@ class Solution {
90
90
}
91
91
```
92
92
93
+ ### ** JavaScript**
94
+
95
+ ``` js
96
+ /**
97
+ * @param {string} s
98
+ * @param {number} minJump
99
+ * @param {number} maxJump
100
+ * @return {boolean}
101
+ */
102
+ var canReach = function (s , minJump , maxJump ) {
103
+ let n = s .length ;
104
+ let dp = new Array (n).fill (0 );
105
+ let sum = new Array (n + 1 ).fill (0 );
106
+ dp[0 ] = 1 ;
107
+ sum[1 ] = 1 ;
108
+ for (let i = 1 ; i < n; i++ ) {
109
+ if (s .charAt (i) == ' 0' ) {
110
+ let left = Math .max (0 , i - maxJump);
111
+ let right = i - minJump;
112
+ if (left <= right && sum[right + 1 ] - sum[left] > 0 ) {
113
+ dp[i] = 1 ;
114
+ }
115
+ }
116
+ sum[i + 1 ] = sum[i] + dp[i];
117
+ }
118
+ return dp .pop ();
119
+ };
120
+ ```
121
+
93
122
### ** ...**
94
123
95
124
```
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } s
3
+ * @param {number } minJump
4
+ * @param {number } maxJump
5
+ * @return {boolean }
6
+ */
7
+ var canReach = function ( s , minJump , maxJump ) {
8
+ let n = s . length ;
9
+ let dp = new Array ( n ) . fill ( 0 ) ;
10
+ let sum = new Array ( n + 1 ) . fill ( 0 ) ;
11
+ dp [ 0 ] = 1 ;
12
+ sum [ 1 ] = 1 ;
13
+ for ( let i = 1 ; i < n ; i ++ ) {
14
+ if ( s . charAt ( i ) == '0' ) {
15
+ let left = Math . max ( 0 , i - maxJump ) ;
16
+ let right = i - minJump ;
17
+ if ( left <= right && sum [ right + 1 ] - sum [ left ] > 0 ) {
18
+ dp [ i ] = 1 ;
19
+ }
20
+ }
21
+ sum [ i + 1 ] = sum [ i ] + dp [ i ] ;
22
+ }
23
+ return dp . pop ( ) ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments