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 | 31 |
Tags
- Binary Tree
- Binary Search
- geometry
- Matrix
- dynamic programming
- greedy
- Class
- database
- bit manipulation
- java
- two pointers
- Math
- hash table
- Method
- Number Theory
- Stack
- Counting
- array
- 파이썬
- Data Structure
- 구현
- 코딩테스트
- 코테
- string
- Tree
- implement
- sorting
- SQL
- 자바
- simulation
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2729. Check if The Number is Fascinating 본문
1. Input
1) int n
- 3자리 자연수이다.
2. Output
1) n과 2*n, 3*n을 이어 붙여 9자리 자연수를 만들었을 때, 매혹적인 수가 된다면 true, 아니면 false를 반환
- 매혹적인 수란 1부터 9까지의 수를 모두 1개씩 갖고 있고, 0이 없는 수를 말한다.
3. Constraint
1) 100 <= n <= 999
4. Example
Input: n = 192 -> Output: true
설명: 192와 2*192=384, 3*192=576을 이어 붙여 만든 수 192384576은 조건을 만족하므로 true를 반환한다.
5. Code
class Solution {
public boolean isFascinating(int n) {
if(n%10==0) return false;
int[] d = new int[10];
for(int i=1 ; i<=3 ; i++){
int x = n*i;
while(x>0){
d[x%10]++;
x /= 10;
}
}
if(d[0]!=0) return false;
for(int i=1 ; i<10 ; i++)
if(d[i]!=1) return false;
return true;
}
}
- 100%, 98%
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2739. Total Distance Traveled (0) | 2023.06.30 |
---|---|
[LeetCode/Easy] 2733. Neither Minimum nor Maximum (0) | 2023.06.30 |
[LeetCode/Easy] 2717. Semi-Ordered Permutation (0) | 2023.06.30 |
[LeetCode/Easy] 2716. Minimize String Length (0) | 2023.06.30 |
[LeetCode/Easy] 2710. Remove Trailing Zeros From a String (0) | 2023.06.30 |