We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5d4f435 commit 37c6defCopy full SHA for 37c6def
jumpGameII.java
@@ -0,0 +1,33 @@
1
+//O(n) time complexity
2
+
3
+public class Solution {
4
+ public int jump(int[] A) {
5
+ if(A==null||A.length==0||A.length==1){
6
+ return 0;
7
+ }
8
9
+ int start = 0;
10
+ int end = 0;
11
+ int jump_times = 0;
12
+ int max = 0;
13
14
15
+ while(end<A.length) {
16
+ max = 0;
17
+ jump_times++;
18
+ //find the max can be reached by current scope
19
+ for(int i=start;i<=end;i++) {
20
+ if((A[i]+i)>=(A.length-1)) {
21
+ return jump_times;
22
23
+ if((A[i]+i)>max) {
24
+ max = A[i]+i;
25
26
27
+ //update for the next search
28
+ start = end + 1;
29
+ end = max;
30
31
32
33
+}
0 commit comments