
- 난이도: Lv1
 
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/147355
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/1/147355. 크키가 작은 부분 문자열


풀이 시간 : 36분
import java.util.*;
class Solution {
    public int solution(String t, String p) {
        int answer = 0;
        
        
        for(int i=0; i<p.length(); i++){
            
            String tCut = t.substring(i, i+p.length());
            
            if(tCut.compareTo(p) <= 0){
                answer++;
            }
        }
        
        
        return answer;
    }
}

//before
 for(int i=0; i<p.length(); i++){
//after        
for(int i=0; i <= t.length() - p.length(); i++){
풀이 시간 : 49분(첫 풀이 시간 포함)
import java.util.*;
class Solution {
    public int solution(String t, String p) {
        int answer = 0;
        
        for(int i=0; i <= t.length() - p.length(); i++){
            
            String tCut = t.substring(i, i+p.length());
            
            if(tCut.compareTo(p) <= 0){
                answer++;
            }
        }
        
        return answer;
    }
}


