코테/LeetCode
2185. Counting Words With a Given Prefix
jhss9747
2025. 1. 9. 11:58
https://leetcode.com/problems/counting-words-with-a-given-prefix/
주어진 접두어로 단어세기.
이번 일일 문제는 너무 간단해서 딱히 쓸 말이 없다
class Solution {
public int prefixCount(String[] words, String pref) {
int count = 0;
for(String text : words){
// 문자열의 첫머리가 pref와 일치한다면
if(text.startsWith(pref)){
count++;
}
}
return count;
}
}