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
- mysql
- 위상정렬
- 정렬
- 자료구조
- 99클럽
- generic class
- LeetCode
- 코딩테스트
- 알고리즘
- 공개키 암호화
- spring
- python
- jsp
- 개발자취업
- DB
- dbms
- Sort
- 99클럽 #코딩테스트준비 #개발자취업 #항해99 #til
- sql
- Java
- JPA
- javascript
- Algorithm
- 코테
- 코딩테스트준비
- til
- 크루스칼
- js
- 가상컴퓨팅
- 항해99
Archives
- Today
- Total
PLOD
[Leetcode] 2283. Check if Number Has Equal Digit Count and Digit Value 본문
대외 활동 및 IT 지식/알고리즘 문제 풀이 정리
[Leetcode] 2283. Check if Number Has Equal Digit Count and Digit Value
훌룽이 2026. 3. 20. 22:06🔗 문제 링크
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/description/
Check if Number Has Equal Digit Count and Digit Value - LeetCode
Can you solve this real interview question? Check if Number Has Equal Digit Count and Digit Value - You are given a 0-indexed string num of length n consisting of digits. Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] t
leetcode.com
✅ 코드
import java.util.*;
class Solution {
public boolean digitCount(String num) {
boolean answer = true;
char[] numCharList = num.toCharArray();
for(int i = 0; i < numCharList.length; i++){
char n = (char)(i + '0');
int cnt = 0;
System.out.println(n);
for(int j = 0; j < numCharList.length; j++){
if(numCharList[j] == n){
cnt++;
}
}
if(cnt != numCharList[i] - '0'){
answer = false;
break;
}
}
return answer;
}
}
💡 배운 점 & 느낀 점
1. int → char : 문자에 '0'을 더해주는 방법으로 타입 캐스팅을 한다
int num = 3;
char numChar = (char)(num+'0');
2. char → int : 숫자에 '0'을 빼주는 방법으로 타입 캐스팅을 한다
char newChar = 'A'
int newInt = newChar - '0''대외 활동 및 IT 지식 > 알고리즘 문제 풀이 정리' 카테고리의 다른 글
| [백준] 평행선(2358) (0) | 2026.03.23 |
|---|---|
| [Leetcode] 187. Repeated DNA Sequences (0) | 2026.03.23 |
| [백준] 좌표 압축(18870) (0) | 2026.03.09 |
| [백준] 파일 정리(20291) (0) | 2026.03.09 |
| [백준] 식당 메뉴(26043) (0) | 2026.02.25 |
Comments