Skip to content

Commit

Permalink
https://leetcode.com/problems/climbing-stairs/description/
Browse files Browse the repository at this point in the history
  • Loading branch information
s50600822 committed Nov 4, 2023
1 parent bb14c64 commit 2e98b0e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package hoa.can.code.ez;

/**
* <a href="https://leetcode.com/problems/climbing-stairs/">desc</a>
*/
public class ClimbStairs {
public int climbs(int n) {
if (n <= 2) {
return n;
}

int[] dp = new int[n + 1];
dp[1] = 1;
dp[2] = 2;

for (int i = 3; i <= n; i++) {
// either one or two steps away
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hoa.can.code;

import hoa.can.code.ez.ClimbStairs;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ClimbStartsTest {
ClimbStairs sol = new ClimbStairs();

@Test
@DisplayName("https://leetcode.com/problems/climbing-stairs/")
public void test() {
assertEquals(0, sol.climbs(0));
assertEquals(1, sol.climbs(1));
assertEquals(3, sol.climbs(3));
}
}

0 comments on commit 2e98b0e

Please sign in to comment.