반응형
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
- 문제
무든 arr에 대한 최소공배수를 출력하는 문제다.
- 풀이
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> arr) {
int answer = *max_element(arr.begin(),arr.end());
bool b = false;
while(!b){
b = true;
for(auto a : arr){
if(answer % a != 0){
b = false;
break;
}
}
answer++;
}
answer--;
return answer;
}
거의 O(n^2)의 느낌으로 풀었다.
- 기억할 것!
X
반응형
'Algorithm > 프로그래머스' 카테고리의 다른 글
프로그래머스 예상 대진표 C++ (0) | 2022.10.21 |
---|---|
프로그래머스 베스트앨범 C++ (0) | 2022.10.14 |
프로그래머스 구명보트 C++ (0) | 2022.10.14 |
프로그래머스 짝지어 제거하기 C++ (0) | 2022.10.13 |
프로그래머스 영어 끝말잇기 C++ (0) | 2022.10.13 |