Skip to content

Commit c56a9f0

Browse files
Added 70. Climbing Stairs Java (#71)
* Udating README.md (Added 70.Climbing Stairs) * 70. Climbing Stairs(Java) * Optimising 70. Climbing Stairs to O(1) space * Changed space complexity of 70. Climbing Stairs
1 parent 6c42f65 commit c56a9f0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Java/climbing-stairs.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int climbStairs(int n) {
3+
int prev1=1, prev2=2, cur=0;
4+
if(n<=2) return n;
5+
for(int i=3;i<=n;++i) {
6+
cur=prev1+prev2;
7+
prev1=prev2;
8+
prev2=cur;
9+
}
10+
return cur;
11+
}
12+
}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
291291
| 72 | [Edit Distance](https://leetcode.com/problems/edit-distance/) | [Python](./Python/edit-distance.py) | _O(N\*M)_ | _O(n^2)_ | Medium | Levenshtein Distance | |
292292
| 91 | [Decode ways](https://leetcode.com/problems/decode-ways/) | [Python](./Python/decode-ways.py) | _O(N)_ | _O(N)_ | Easy | DP | |
293293
| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game/) | [Python](./Python/divisor-game.py) | _O(N^2)_ | _O(N)_ | Easy | DP | |
294+
| 070 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | [Java](./Java/climbing-stairs.java) | _O(N)_ | _O(1)_ | Easy | DP | |
294295

295296
<br/>
296297
<div align="right">

0 commit comments

Comments
 (0)