[프로그래머스, 181871] 문자열이 몇 번 등장하는지 세기 (java)
Problem Solving/Programmers

[프로그래머스, 181871] 문자열이 몇 번 등장하는지 세기 (java)

728x90

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

 

프로그래머스

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

programmers.co.kr

728x90

메모리: 71.4 MB, 시간: 0.14 ms

사용 알고리즘: 문자열

class Solution {
    public int solution(String myString, String pat) {
        
        int answer = 0;
        
        for(int i = 0; i <= myString.length() - pat.length(); i++) {
            if(myString.substring(i, i + pat.length()).equals(pat))
                answer++;
        }
        
        return answer;
    }
}
728x90