Skip to content

Commit 5439322

Browse files
committed
feat: climbing stairs
1 parent 7fbc074 commit 5439322

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

climbing-stairs/minji-go.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Problem: https://leetcode.com/problems/climbing-stairs/
3+
Description: how many distinct ways can you climb to the top, if you can either climb 1 or 2 steps
4+
Concept: Dynamic Programming, Memoization, Recursion, Math, Array, Iterator, Combinatorics ...
5+
Time Complexity: O(n), Runtime: 0ms
6+
Space Complexity: O(1), Memory: 40.51MB
7+
*/
8+
class Solution {
9+
public int climbStairs(int n) {
10+
int step1=1, step2=2;
11+
for(int i=3; i<n; i++){
12+
int step3=step1+step2;
13+
step1=step2;
14+
step2=step3;
15+
}
16+
return n==1?step1:step2;
17+
}
18+
}

0 commit comments

Comments
 (0)