Skip to content

Commit 4e87ee1

Browse files
Add files via upload
1 parent 0a6a449 commit 4e87ee1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

climbing-stairs.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public int climbStairs(int n) {
3+
int a=2,b=1,temp=0;
4+
if(n==1)
5+
{
6+
return b;
7+
}
8+
if(n==2)
9+
{
10+
return a;
11+
}
12+
for(int i=3;i<=n;i++)
13+
{
14+
temp=a+b;
15+
b=a;
16+
a=temp;
17+
if(i==n)
18+
{
19+
break;
20+
}
21+
}
22+
return temp;
23+
}
24+
}

0 commit comments

Comments
 (0)