9월 15일 금요일 알고리즘 코드리뷰 #3
Closed
minseo9974
started this conversation in
Ideas
Replies: 5 comments 7 replies
-
public static long factorial(int number) {
if (number < 0) {
throw new IllegalArgumentException("not negative");
}
switch (number) {
case 0:
return 1;
default:
return number * factorial(number - 1);
}
}
public static long fibonacci(int number) {
if (number < 0) {
throw new IllegalArgumentException("not negative");
}
switch (number) {
case 0:
return 0;
case 1:
return 1;
default:
return number + fibonacci(number - 1);
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
-
public static long factorial(int number) {
switch (number) {
case 1:
return 1;
default:
return number * factorial(number - 1);
}
}
public static long fibonacci(int number) {
switch (number) {
case 1:
return 1;
case 2:
return 1;
default:
return fibonacci(number - 1) + fibonacci(number - 2);
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
public static long factorial(int number) {
if (number < 0)
throw new IllegalArgumentException("Input Negative Number Error");
switch (number) {
case 0:
return 1;
default:
return number * factorial(number - 1);
}
}
public static long fibonacci(int number) {
switch (number) {
case 0:
return 0;
case 1:
case 2:
return 1;
default:
return fibonacci(number - 1) + fibonacci(number - 2);
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
public static long factorial(int number) {
if(number < 0){
throw new IllegalArgumentException("Negative Num");
}
switch (number) {
case 0:
return 1;
default:
return number * factorial(number - 1);
}
}
public static long fibonacci(int number) {
if(number < 0)
throw new IllegalArgumentException("Negative Num");
switch (number) {
case 0:
return 0;
case 1:
return 1;
default:
return fibonacci(number - 1) + fibonacci(number - 2);
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
고생하셨습니다 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Recursion
Beta Was this translation helpful? Give feedback.
All reactions