153. k의 개수

김해준's avatar
Dec 30, 2025
153. k의 개수

사용언어 : Java

문제
notion image
풀이
/* k == 1 1~13 1 2 3 4 5 6 7 8 9 10 11 12 13 o o o o o 이게 왜 결과값이 6이지 11은 2번으로 체크하나 for로 i부터 j까지 돌리고 안에서 while로 %10하면서 한자씩 끊어서 k랑 같은지 비교해야될거같은데 이렇게 하면 위에 결과값이 6이 나오긴 하네 */ class Solution { public int solution(int i, int j, int k) { int answer = 0; for(int a = i ; a <= j ; a++) { int temp = a; while(temp > 0) { int result = temp % 10; if(result == k) answer++; temp /= 10; } } return answer; } }
notion image
Share article