MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / climbStairs

Method climbStairs

Java/climbing-stairs.java:2–11  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

1class 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected