728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/12953
코딩테스트 연습 - N개의 최소공배수
두 수의 최소공배수(Least Common Multiple)란 입력된 두 수의 배수 중 공통이 되는 가장 작은 숫자를 의미합니다. 예를 들어 2와 7의 최소공배수는 14가 됩니다. 정의를 확장해서, n개의 수의 최소공배
programmers.co.kr
public class Solution {
public int solution(int[] arr) {
int answer = LeastCommonMultiple(arr);
return answer;
}
int LeastCommonMultiple(int[] arr)
{
int lcm = 1;
bool isFinished = false;
while (!isFinished)
{
isFinished = true;
for (int i = -1; ++i < arr.Length;)
if (lcm % arr[i] != 0)
{
++lcm;
isFinished = false;
}
}
return lcm;
}
}
최소공배수의 개념이 생겨서 2단계인 건가..
반응형
'프로그래머스_C# > Level_2' 카테고리의 다른 글
[프로그래머스 C#] 최댓값과 최솟값 (0) | 2021.10.29 |
---|---|
[프로그래머스 C#] 최솟값 만들기 (0) | 2021.10.28 |
[프로그래머스 C#] 피보나치 수 (0) | 2021.10.27 |
[프로그래머스 C#] 행렬의 곱셈 (0) | 2021.10.26 |
[프로그래머스 C#] JadenCase 문자열 만들기 (0) | 2021.10.25 |