웅재의 코딩세상
[프로그래머스] 배열 만들기 2 본문
- 풀이
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int l, int r){
vector<int> answer;
for (int i = l; i <= r; i++){
string tmp = to_string(i);
bool check = true;
for (char c : tmp){
if (c != '0' && c != '5'){
check = false;
break;
}
}
if (check){
answer.push_back(i);
}
}
if (empty(answer)){
answer.push_back(-1);
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 수열과 구간 쿼리 2 (0) | 2024.01.29 |
---|---|
[프로그래머스] 배열 만들기 4 (0) | 2024.01.29 |
[프로그래머스] 콜라츠 수열 만들기 (1) | 2024.01.26 |
[프로그래머스] 수 조작하기 2 (0) | 2024.01.26 |
[프로그래머스] 마지막 두 원소 (0) | 2024.01.26 |