슈콩

[프로그래머스] Lv.1 크기가 작은 부분 문자열 본문

Algorithms/Programmers

[프로그래머스] Lv.1 크기가 작은 부분 문자열

shukong 2025. 10. 11. 20:42

[문제]

https://school.programmers.co.kr/learn/courses/30/lessons/147355

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

[소스 코드]

class Solution {
    public int solution(String t, String p) {
        int answer = 0;
        int n = p.length();
        long target = Long.parseLong(p); // p를 long으로 변환

        for (int i = 0; i <= t.length() - n; i++) {
            String s = t.substring(i, i + n);
            long value = Long.parseLong(s); // 부분 문자열도 long으로 변환
            if (value <= target) answer++;
        }

        return answer;
    }
}