File tree 2 files changed +29
-8
lines changed
2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change 1
- def canJump (nums ):
2
- n = len (nums )
3
- max_reach = 0
1
+ from typing import List
4
2
5
- for i in range ( n ) :
6
- if i > max_reach :
7
- return False
8
- max_reach = max ( max_reach , i + nums [ i ])
3
+ class Solution :
4
+ def canJump ( self , nums : List [ int ]) -> bool :
5
+ n = len ( nums )
6
+ max_reach = 0
9
7
10
- return True
8
+ for i in range (n ):
9
+ ## 能不能到达重点的本质是 max_reach 和 i 的比较。
10
+ if i > max_reach :
11
+ return False
12
+ max_reach = max (max_reach , i + nums [i ])
13
+
14
+ return True
15
+
16
+
17
+ nums = [3 ,2 ,1 ,0 ,1 ]
18
+ print (Solution ().canJump (nums ))
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def canJump (self , nums ):
3
+ max_reach = 0
4
+ for i in nums :
5
+ if i > max_reach :
6
+ return False
7
+ max_reach = max (max_reach , nums [i ] + i )
8
+ return True
9
+
10
+
11
+
12
+ nums = [3 ,2 ,1 ,0 ,1 ]
13
+ print (Solution ().canJump (nums ))
You can’t perform that action at this time.
0 commit comments