Skip to content

Commit 81896aa

Browse files
authored
Create Solution.java
1 parent 15eaf22 commit 81896aa

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

solution/0509.Fibonacci/Solution.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int fib(int N) {
3+
if (N < 2) {
4+
return N;
5+
}
6+
int a = 0, b = 1;
7+
int res = 0;
8+
for (int i = 2; i <= N; ++i) {
9+
res = a + b;
10+
a = b;
11+
b = res;
12+
}
13+
return res;
14+
}
15+
}

0 commit comments

Comments
 (0)