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
- 코테
- 파이썬
- two pointers
- 코딩테스트
- 자바
- SQL
- Counting
- Binary Tree
- greedy
- array
- dynamic programming
- Binary Search
- Tree
- Math
- Number Theory
- Matrix
- Stack
- java
- 구현
- simulation
- bit manipulation
- Method
- sorting
- string
- geometry
- Class
- database
- Data Structure
- hash table
- implement
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2283. Check if Number Has Equal Digit Count and Digit Value 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 2283. Check if Number Has Equal Digit Count and Digit Value
무지맘 2023. 1. 16. 01:181. Input
1) String num
2. Output
1) [0, num.length)에 있는 모든 i에 대해서 i가 num[i]번 나타나면 true, 아니면 false를 반환
3. Constraint
1) 1 <= num.length <= 10
2) num은 숫자로 이루어져 있다.
4. Example
Input: num = "1210" -> Output: true
설명:
- 0번째 숫자: 1 -> 0이 1번 나타났나? -> O
- 1번째 숫자: 2 -> 1이 2번 나타났나? -> O
- 2번째 숫자: 1 -> 2가 1번 나타났나? -> O
- 3번째 숫자: 0 -> 3이 0번 나타났나? -> O
- 모든 경우가 맞으므로 true를 반환한다.
5. Code
1) 첫 코드(2022/08/04)
int[] d = new int[num.length()];
for(int i=0 ; i<num.length() ; i++){
int c = num.charAt(i)-'0';
if(c>=num.length())
return false;
d[c]++;
}
for(int i=0 ; i<num.length() ; i++){
if(d[i]!=(num.charAt(i)-'0'))
return false;
}
return true;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2315. Count Asterisks (0) | 2023.01.16 |
---|---|
[LeetCode/Easy] 2299. Strong Password Checker II (0) | 2023.01.16 |
[LeetCode/Easy] 2278. Percentage of Letter in String (0) | 2023.01.16 |
[LeetCode/Easy] 2269. Find the K-Beauty of a Number (0) | 2023.01.16 |
[LeetCode/Easy] 2264. Largest 3-Same-Digit Number in String (0) | 2023.01.16 |