Skip to content

Commit 6b4625b

Browse files
authored
[20251030] PGM / LV2 / N개의 최소공배수 / 이인희
1 parent 0f85284 commit 6b4625b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int[] arr) {
6+
long lcm = arr[0];
7+
for(int i=1; i<arr.length; i++){
8+
lcm = lcm(lcm, arr[i]);
9+
}
10+
return (int)lcm;
11+
}
12+
private static long gcd(long a, long b){
13+
while(b != 0){
14+
long t = a % b;
15+
a = b;
16+
b = t;
17+
}
18+
return a;
19+
}
20+
private static long lcm(long a, long b){
21+
return (a / gcd(a, b)) * b;
22+
}
23+
}
24+
25+
```

0 commit comments

Comments
 (0)