https://school.programmers.co.kr/learn/courses/30/lessons/120871
내 풀이
class Solution {
public int solution(int n) {
int answer = 0;
for(int i = 1; i<=n; i++){
answer++;
while(answer % 3 == 0 || (answer + "").contains("3")) answer++;
}
return answer;
}
}
다른분 풀이
String.valueOf 함수를 몰라서 ""붙여서 사용했다. 그치만 내장함수가 있다면 활용하는 것도 좋을 것 같아서 기억해두면 유용할 것 같다.
class Solution {
public int solution(int n) {
int answer = 0;
for (int i = 1; i <= n; i++) {
answer++;
if (answer % 3 == 0 || String.valueOf(answer).contains("3")) {
i--;
}
}
return answer;
}
}
'코딩테스트 > Programmers' 카테고리의 다른 글
[프로그래머스] 정수 내림차순으로 배치하기 (0) | 2025.02.20 |
---|---|
[프로그래머스] 문자열을 정수로 바꾸기 (0) | 2025.02.18 |
[프로그래머스] 특이한 정렬 (1) | 2025.01.30 |
[프로그래머스] 최빈값 구하기 (0) | 2025.01.29 |
[프로그래머스] PCCE 기출문제 10번 / 데이터 분석 (0) | 2025.01.26 |