숫자 찾기

han.user();·2023년 4월 1일
0

프로그래머스

목록 보기
22/87
post-thumbnail

class Solution {
    public int solution(int num, int k) {
        int answer = 0;
        int result = 0;

        String str = Integer.toString(num);

        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (Character.isDigit(c)) {
                answer = Character.getNumericValue(c);
                if (answer == k) {
                    result = i + 1;
                    break;
                } else {
                    result = -1;
                }
            }
        }
        return result;
    }
}
profile
I'm still hungry.

0개의 댓글