[LintCode] Fibonacci
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