프로그래머스 - 피보나치 수
Contents
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public class Fibonacci {
public long fibonacci(int num) {
if(num==0) {
return 0;
}
else if(num==1){
return 1;
}
else{
return fibonacci(num-1)+fibonacci(num-2);
}
}
// 아래는 테스트로 출력해 보기 위한 코드입니다.
public static void main(String[] args) {
Fibonacci c = new Fibonacci();
int testCase = 3;
System.out.println(c.fibonacci(testCase));
}
} |
다음에는 dp로 풀어봐야겠다.
Author Jaejin Jang
LastMod 2017-12-23
License Jaejin Jang