Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int fib(int N) {
- if (N == 0) {
- return 0;
- }
- if (N <= 2) {
- return 1;
- }
- int a = 1;
- int b = 1;
- int t;
- for (int i = 2; i < N; i++) {
- t = b;
- b += a;
- a = t;
- }
- return b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement