728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import java.math.BigInteger; //int의 범위를 넘는 수가 나오므로 biginteger 사용
class Solution {
public BigInteger solution(int balls, int share) {
return fac(balls).divide((fac(balls-share).multiply(fac(share)))); //hint 에 써있는 공식대로 입력
}
public BigInteger fac(int num) { //팩토리얼을 실행해주는 메소드
BigInteger big=new BigInteger("1"); //1부터 시작
for(int i=1; i<=num; i++) {
big=big.multiply(new BigInteger(Integer.toString(i))); //1부터 n까지 차례대로 곱해줌
}
return big;
}
}
|
cs |
반응형
728x90
반응형
'[JAVA] 프로그래머스 스쿨 > Java Lv.0' 카테고리의 다른 글
[프로그래머스/Java] Lv.0 2차원으로 만들기 (0) | 2022.11.22 |
---|---|
[프로그래머스/Java] Lv.0 점의 위치 구하기 (0) | 2022.11.21 |
[프로그래머스/Java] Lv.0 가위 바위 보 (1) | 2022.11.20 |
[프로그래머스/Java] Lv.0 개미 군단 (0) | 2022.11.20 |
[프로그래머스/Java] Lv.0 순서쌍의 개수 (0) | 2022.11.20 |