Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- greedy
- two pointers
- Binary Search
- hash table
- Data Structure
- Number Theory
- array
- Binary Tree
- java
- Matrix
- string
- 파이썬
- simulation
- 구현
- Math
- Counting
- SQL
- database
- bit manipulation
- Class
- implement
- dynamic programming
- Method
- 코테
- Stack
- sorting
- geometry
- Tree
- 코딩테스트
- 자바
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.0] 저주의 숫자 3 본문
1. Input, Output, Example
3x 마을 사람들은 3을 저주의 숫자라고 생각하기 때문에 3의 배수와 숫자 3을 사용하지 않는다.
- n을 3x 마을에서 사용하는 숫자로 바꿔 반환
2. Constraint
1) 1 ≤ n ≤ 100
3. Code
1) 첫 코드(2023/05/30)
import java.util.*;
class Solution {
public int solution(int n) {
int i = 1;
List<Integer> list = new ArrayList<>();
while(list.size()<n){
boolean check = false;
if(i%3==0)
check = true;
int num = i;
while(num>1 && !check){
if(num%10==3)
check = true;
num /= 10;
}
if(!check) list.add(i);
i++;
}
return list.get(n-1);
}
}
2) 다른 사람의 풀이 중 마음에 들었던 것(2023/05/30)
class Solution {
public int solution(int n) {
String str;
for (int i = 1; i <= n; i++){
str = String.valueOf(i);
if(str.contains("3") || i%3 == 0) n++;
}
return n;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 830. Positions of Large Groups (0) | 2023.05.31 |
---|---|
[LeetCode/Easy] 783. Minimum Distance Between BST Nodes (0) | 2023.05.31 |
[프로그래머스/Lv.0] 등수 매기기 (0) | 2023.05.30 |
[LeetCode/Easy] 706. Design HashMap (0) | 2023.05.30 |
[LeetCode/Easy] 703. Kth Largest Element in a Stream (0) | 2023.05.30 |