File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Problem source: https://leetcode.com/problems/jump-game-ii/?envType=study-plan-v2&envId=top-interview-150
2
+ from typing import List
3
+
4
+
5
+ class Solution :
6
+ def jump (self , nums : List [int ]) -> int :
7
+ # variable storing the required answer
8
+ n_jumps = 0
9
+
10
+ # 2 pointers
11
+ start = 0
12
+ end = 0
13
+
14
+ while end < len (nums ) - 1 :
15
+ max_jump_possible = 0
16
+
17
+ for i in range (start , end + 1 ):
18
+ max_jump_possible = max (max_jump_possible , i + nums [i ])
19
+
20
+ # update the pointers
21
+ start = end + 1
22
+ end = max_jump_possible
23
+
24
+ # update the number of jumps
25
+ n_jumps += 1
26
+
27
+ return n_jumps
Original file line number Diff line number Diff line change
1
+ # Problem source: https://leetcode.com/problems/h-index/description/
2
+ from typing import List
3
+
4
+
5
+ class Solution :
6
+ def hIndex (self , citations : List [int ]) -> int :
7
+ citations .sort (reverse = True )
8
+ l = len (citations )
9
+ h = 0
10
+
11
+ for i in range (l ):
12
+ if citations [i ] >= i + 1 :
13
+ h = i + 1
14
+
15
+ return h
You can’t perform that action at this time.
0 commit comments