diff --git a/Java/climbing-stairs.java b/Java/climbing-stairs.java new file mode 100644 index 00000000..d5173cd4 --- /dev/null +++ b/Java/climbing-stairs.java @@ -0,0 +1,12 @@ +class Solution { + public int climbStairs(int n) { + int prev1=1, prev2=2, cur=0; + if(n<=2) return n; + for(int i=3;i<=n;++i) { + cur=prev1+prev2; + prev1=prev2; + prev2=cur; + } + return cur; + } +} diff --git a/README.md b/README.md index ed18e92a..0f4164a4 100644 --- a/README.md +++ b/README.md @@ -291,6 +291,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 72 | [Edit Distance](https://leetcode.com/problems/edit-distance/) | [Python](./Python/edit-distance.py) | _O(N\*M)_ | _O(n^2)_ | Medium | Levenshtein Distance | | | 91 | [Decode ways](https://leetcode.com/problems/decode-ways/) | [Python](./Python/decode-ways.py) | _O(N)_ | _O(N)_ | Easy | DP | | | 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game/) | [Python](./Python/divisor-game.py) | _O(N^2)_ | _O(N)_ | Easy | DP | | +| 070 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | [Java](./Java/climbing-stairs.java) | _O(N)_ | _O(1)_ | Easy | DP | |