Skip to content

Commit 6235617

Browse files
committedJan 11, 2019
add 0509 folder & cpp version
1 parent 5acb0e8 commit 6235617

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎solution/0509.Fibonacci/Solution.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int fib(int N) {
4+
if (N < 2)
5+
return N > 0? 1: 0 ;
6+
int aN_2 = 0, aN_1 = 1, aN ;
7+
while (--N)
8+
{
9+
aN = aN_2 + aN_1 ;
10+
aN_2 = aN_1 ;
11+
aN_1 = aN ;
12+
}
13+
return aN ;
14+
}
15+
};

0 commit comments

Comments
 (0)