class Solution {
public int prefixCount(String[] words, String pref) {
int res = 0;
for (String word : words) {
if (isEqual(word, pref)) res++;
}
return res;
}
// 判断b是否是a的前缀
boolean isEqual(String a, String b) {
if (a.length() < b.length()) return false;
for (int i = 0; i < b.length(); i++) {
if (b.charAt(i) != a.charAt(i)) return false;
}
return true;
}
}
标签:return,前缀,int,res,给定,2185,String
From: https://www.cnblogs.com/eiffelzero/p/17035286.html