Skip to content

Commit

Permalink
add Fibonacci.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
YuYinCUG committed Oct 30, 2016
1 parent 0bb801e commit dd499f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Fibonacci.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//斐波那契数列

int Fibonacci(n)
{
int result[2] = {0, 1};

if(n < 2)
{
return result[n];
}

long long fibNMinusOne = 1;
long long fibNMinusTwo = 0;
long long fibN = 0;
for(unsigned int i = 2; i <= n; ++ i)
{
fibN = fibNMinusOne + fibNMinusTwo;
fibNMinusTwo = fibNMinusOne;
fibNMinusOne = fibN;
}
return fibN;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 剑指offer题集

- [面试题4:从尾到头打印链表](https://github.com/YuYinCUG/jianzhioffer/blob/master/PrintListReversingly.cpp)
- [面试题9:斐波那契数列](https://github.com/YuYinCUG/jianzhioffer/blob/master/Fibonacci.cpp)
- [面试题13:在O(1)时间删除链表结点](https://github.com/YuYinCUG/jianzhioffer/blob/master/DeleteNode.cpp)
- [面试题16:反转链表](https://github.com/YuYinCUG/jianzhioffer/blob/master/ReverseList.cpp)
- [面试题35:第一个只出现一次的字符](https://github.com/YuYinCUG/jianzhioffer/blob/master/FirstNotRepeatingChar.cpp)
Expand Down

0 comments on commit dd499f8

Please sign in to comment.