๐ 509. ๆๆณข้ฃๅฅๆฐ
2022ๅนด6ๆ9ๆฅๅฐไบ 1 ๅ้
๐ 509. ๆๆณข้ฃๅฅๆฐ
้พๅบฆ๏ผ ๐
้ฎ้ขๆ่ฟฐ
่งฃๆณ
class Solution {
public int fib(int n) {
// ็นๆฎๆ
ๅต็นๅค
if(n == 0) {
return 0;
}
if(n == 1) {
return 1;
}
// n >= 2
int a = 0;
int b = 1;
int c = 1;
for(int i = 2; i <= n; i ++) {
c = a + b;
a = b;
b = c;
}
return c;
}
}