본문 바로가기

Problem Solving/리트코드(leetcode)

[Leetcode/C++] 509. Fibonacci Number


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/

 

Fibonacci Number - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com