首页 > 其他分享 >2185. 统计包含给定前缀的字符串

2185. 统计包含给定前缀的字符串

时间:2023-01-08 20:33:25浏览次数:72  
标签:return 前缀 int res 给定 2185 String

2185. 统计包含给定前缀的字符串

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

相关文章