Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit afb3cdb

Browse files
ADD Climbing-Stairs problem #56
1 parent f7e6410 commit afb3cdb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

‎Easy/climbing-stairs.cs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
3+
public class Solution
4+
{
5+
private static int _GetFibonacciNumber(int n)
6+
{
7+
int prev = 1;
8+
int curr = 1;
9+
for (int i = 0; i < n - 1; i++)
10+
{
11+
int temp = curr;
12+
curr += prev;
13+
prev = temp;
14+
}
15+
16+
return curr;
17+
}
18+
19+
public static int ClimbStairs(int n)
20+
{
21+
if (n < 1 || n > 45)
22+
{
23+
return 0;
24+
}
25+
26+
return _GetFibonacciNumber(n);
27+
}
28+
29+
public static void Main(string[] args)
30+
{
31+
Console.WriteLine(ClimbStairs(4));
32+
33+
Console.ReadKey();
34+
}
35+
}
36+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /