inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 276. N개의 최소공배수

    프로그래머스 (12953)
    Stupefyee's avatar
    Stupefyee
    May 23, 2025
    [JAVA 문제 풀이] 276. N개의 최소공배수
    Contents
    내가 작성한 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/12953
    notion image
     

    내가 작성한 코드

    class Solution { // 최대공약수 (GCD) public int gcd(int a, int b) { while (b != 0) { int tmp = b; b = a % b; a = tmp; } return a; } // 최소공배수 (LCM) public int lcm(int a, int b) { return a * b / gcd(a, b); } public int solution(int[] arr) { int answer = arr[0]; for (int i = 1; i < arr.length; i++) { answer = lcm(answer, arr[i]); } return answer; } }
    Share article
    Contents
    내가 작성한 코드

    stupefyee

    RSS·Powered by Inblog