class Solution {
public:
int fib(int n) {
if(n == 0) return 0;
return n > 1 ? fib(n-1) + fib(n-2) : 1;
}
};
recurrsion (재귀함수) 을 처음 이해하기 가장 좋은 문제입니다.
문제: https://leetcode.com/problems/fibonacci-number/
'Problem Solving > 리트코드(leetcode)' 카테고리의 다른 글
[Leetcode/C++] 169. Majority Element (0) | 2022.02.10 |
---|---|
[Leetcode/C++] 125. Valid Palindrome (0) | 2022.01.28 |
[Leetcode/C++] 412. Fizz Buzz (0) | 2022.01.28 |
[Leetcode/C++] 1154. Day of the Year (0) | 2022.01.28 |
[Leetcode/C++] 1047. Remove All Adjacent Duplicates In String (0) | 2022.01.26 |