Advertisement
ogv

Untitled

ogv
Aug 11th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. class Solution {
  2.     public int fib(int N) {
  3.         if (N == 0) {
  4.             return 0;
  5.         }
  6.         if (N <= 2) {
  7.             return 1;
  8.         }
  9.        
  10.         int a = 1;
  11.         int b = 1;
  12.         int t;
  13.        
  14.         for (int i = 2; i < N; i++) {
  15.             t = b;
  16.             b += a;
  17.             a = t;
  18.         }
  19.        
  20.         return b;
  21.     }    
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement