Machineboy空
프로그래머스 : 저주의 숫자 3 본문
Mine)
- 규칙에 부합하는 숫자 리스트 미리 생성
- n: index값으로 사용
한계) 계산 횟수도 많고, n값 커지면 대응하지 못함
using System;
using System.Collections.Generic;
public class Solution {
public int solution(int n) {
int answer = 0;
List<int> arr = new List<int>();
for (int i = 1; i < 200; i++) {
if (i % 3 != 0 && !i.ToString().Contains("3")) {
arr.Add(i);
}
}
arr.Sort();
answer = arr[n-1];
return answer;
}
}
다른 사람 풀이)
- n: 반복 횟수로 사용
using System;
public class Solution {
public int solution(int n) {
int answer = 0;
int count = 1;
for(int i=0;i<n;i++)
{
answer++;
while(answer%3==0||answer.ToString().Contains("3"))
{
answer++;
}
}
return answer;
}
}
'Computer > Coding Test' 카테고리의 다른 글
1월 3주차 (0) | 2024.01.18 |
---|---|
프로그래머스 : 모음 제거 (0) | 2023.12.30 |
백준 11047: 동전 0 - 그리디 알고리즘 (0) | 2023.12.19 |
1260번: DFS와 BFS (0) | 2023.12.19 |
백준 11724: 연결 요소의 개수 구하기 - DFS(깊이우선탐색) (1) | 2023.10.31 |