Skip to content

Commit 2dafc41

Browse files
committed
add jump game solution
1 parent a197b76 commit 2dafc41

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

jump-game/Tessa1217.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
3+
// 시간 복잡도: O(N), 공간복잡도: O(1)
4+
public boolean canJump(int[] nums) {
5+
6+
int maxJump = 0;
7+
for (int i = 0; i < nums.length; i++) {
8+
// 최대 점프수로 현재 인덱스에 도달할 수 없다면
9+
if (i > maxJump) {
10+
return false;
11+
}
12+
maxJump = Math.max(maxJump, i + nums[i]);
13+
if (maxJump >= nums.length - 1) {
14+
return true;
15+
}
16+
}
17+
18+
return true;
19+
20+
}
21+
}
22+

0 commit comments

Comments
 (0)