题目
给你一个字符串数组 words
和一个字符串 pref
。
返回 words
中以 pref
作为 前缀 的字符串的数目。
字符串 s
的 前缀 就是 s
的任一前导连续字符串。
示例1:
1 | 输入:words = ["pay","attention","practice","attend"], pref = "at" |
示例2:
1 | 输入:words = ["leetcode","win","loops","success"], pref = "code" |
提示:
words[i]
和pref
由小写英文字母组成1 <= words.length <= 100
1 <= words[i].length, pref.length <= 100
解法
解法一:
Java
1 | public int prefixCount(String[] words, String pref) { |