We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
int memo[100]; int fibonacci(int n) { if (n <= 1) { return n; } else { if (memo[n] > 0) { return memo[n]; } memo[n] = fibonacci(n - 1) + fibonacci(n - 2); return memo[n]; } }
class Solution { public int solution(int n) { return fibonacci(n) % 1234567; } private static int fibonacci(int n) { if (n == 0 || n == 1) return n; else return fibonacci(n - 1) + fibonacci(n - 2); } }
package main.java.com.poogle.PG; public class Solution { static int solution(int n) { int ans = 0; int a1 = 1; int a2 = 1; if (n == 1 || n == 2) return 1; else { for (int i = 3; i <= n; i++) { ans = (a1 + a2) % 1234567; a1 = a2; a2 = ans; } return ans; } } public static void main(String[] args) { System.out.println(solution(3)); System.out.println(solution(5)); } }
The text was updated successfully, but these errors were encountered:
d466234
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
시간초과 나는 재귀 풀이
단순 반복문으로 풀이
The text was updated successfully, but these errors were encountered: