Skip to content

Commit

Permalink
https://leetcode.com/problems/jump-game/
Browse files Browse the repository at this point in the history
  • Loading branch information
s50600822 committed Oct 30, 2023
1 parent e62c095 commit f6ee88a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ public static int minJumps(int[] nums) {
}

int maxReach = nums[0];
int steps = 1;
int currentMax = nums[0];

if (currentMax == 0)
return NO_WAY;

for (int currentBase = 1; currentBase < n; currentBase++) {
if (currentMax == 0)
return NO_WAY;
int steps = 1;

for (int currentBase = 1; currentBase < n; currentBase++) {
if(currentMax >= n-1){
steps++;
return steps;
}
if (currentBase > maxReach) {
steps++;
maxReach = currentMax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ public void yesWithDetail() {
int[] case3 = new int[]{1,1,1,1,1,1};
assertEquals(5, JumpingLikeASmartAss.minJumps(case3), "1 -> 1 ->... end");
assertEquals(5, JumpingQuickly.minJumps(case3), "1 -> 1 ->... end");

int[] case4 = new int[]{5,9,3,2,1,0,2,3,3,1,0,0};
assertEquals(3, JumpingLikeASmartAss.minJumps(case4), "...3-> end");
assertEquals(3, JumpingQuickly.minJumps(case4), "...3 -> end");
}

// @Test
// @DisplayName("nope")
// @Disabled
// public void nope() {
// assertEquals(
// 13,
// JumpingLikeASmartAss.minJumps(new int[]{8,2,4,4,4,9,5,2,5,8,8,0,8,6,9,1,1,6,3,5,1,2,6,6,0,4,8,6,0,3,2,8,7,6,5,1,7,0,3,4,8,3,5,9,0,4,0,1,0,5,9,2,0,7,0,2,1,0,8,2,5,1,2,3,9,7,4,7,0,0,1,8,5,6,7,5,1,9,9,3,5,0,7,5}),
// "quick"
// );
// }
@Test
@DisplayName("nope")
@Disabled("TOO SLOW TO CHECK ALL COMBINATIONS")
public void nope() {
assertEquals(
13,
JumpingLikeASmartAss.minJumps(new int[]{8,2,4,4,4,9,5,2,5,8,8,0,8,6,9,1,1,6,3,5,1,2,6,6,0,4,8,6,0,3,2,8,7,6,5,1,7,0,3,4,8,3,5,9,0,4,0,1,0,5,9,2,0,7,0,2,1,0,8,2,5,1,2,3,9,7,4,7,0,0,1,8,5,6,7,5,1,9,9,3,5,0,7,5}),
"quick"
);
}
@Test
@DisplayName("yep")
public void yep() {
Expand Down

0 comments on commit f6ee88a

Please sign in to comment.