[LintCode] Fibonacci
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
public int fibonacci(int n) { // write your code here int first = 0; if(n == 1) return first; int second = 1; if(n == 2) return second; int third = 0; for(int i = 3; i <=n; i++) { third = first+ second; first = second; second = third; } return third; } |
Leave A Comment