File tree 2 files changed +46
-0
lines changed
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 60ms 75.10%
2
+ class Solution :
3
+ def jump (self , nums ):
4
+ """
5
+ :type nums: List[int]
6
+ :rtype: int
7
+ """
8
+ current_index = 0
9
+ step = 0
10
+ max_index = len (nums ) - 1
11
+
12
+ while current_index < max_index :
13
+ if current_index + nums [current_index ] >= max_index :
14
+ step += 1
15
+ return step
16
+ temp_list = nums [current_index + 1 :current_index + 1 + nums [current_index ]]
17
+ temp_list = [num + index for index , num in enumerate (temp_list )]
18
+
19
+ current_index += (temp_list .index (max (temp_list )) + 1 )
20
+ step += 1
21
+
22
+ return step
Original file line number Diff line number Diff line change
1
+ # 44ms 97.44%
2
+ class Solution :
3
+ def canJump (self , nums ):
4
+ """
5
+ :type nums: List[int]
6
+ :rtype: bool
7
+ """
8
+ current_index , len_nums = 0 , len (nums )
9
+ if 0 not in nums :
10
+ return True
11
+ if nums [0 ] is 0 :
12
+ return False if len_nums > 1 else True
13
+
14
+ while True :
15
+ value_list = [index + num for index , num in enumerate (nums [current_index + 1 :current_index + nums [current_index ] + 1 ])]
16
+ max_step = value_list .index (max (value_list )) + 1
17
+
18
+ if current_index + max_step >= len_nums - 1 :
19
+ return True
20
+
21
+ current_index += max_step
22
+
23
+ if nums [current_index ] is 0 :
24
+ return False
You can’t perform that action at this time.
0 commit comments