2 parents 33df0bd + 6b4625b commit 892ef5cCopy full SHA for 892ef5c
1 file changed
LiiNi-coder/202510/30 PGM N개의 최소공배수.md
@@ -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