Count Prefixes of a Given String LeetCode solution in Java
1class Solution {2public int countPrefixes(String[] words, String s) {3int i = 0;4int j = 0;5int count = 0;6for (int k = 0; k < words.length; k++) {7if (words[k].length() > s.length()) {8continue;9}1011while (i < words[k].length() && words[k].charAt(i) == s.charAt(j)) {12i++;13j++;14}15if (i == words[k].length()) {16count++;17}18i = 0;19j = 0;20}21return count;22}23}