문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
문자열 배열 words와 문자열 pref가 주어진다.
words에서 접두어가 pref인 문자열의 수를 반환해라.
문자열 s의 접두어는 s의 부분 문자열이다.
#1
Input: words = ["pay", "attention", "practice", "attend"], pref = "at"
Output: 2
Explanation: 2개의 문자열 "attention", "attend"는 접두어에 "at"을 포함한다.
#2
Input: word = ["leetcode", "win", "loops", "success"], pref = "code"
Output: 0
Explanation: 접두어로 "code"를 포함하는 문자열은 없다.
class Solution {
public int prefixCount(String[] words, String pref) {
int count = 0;
for(String word : words){
if(word.length() >= pref.length() && word.substring(0, pref.length()).equals(pref)){
count++;
}
}
return count;
}
}