Count Prefixes of a Given String LeetCode solution in Java

1
class Solution {
2
public int countPrefixes(String[] words, String s) {
3
int i = 0;
4
int j = 0;
5
int count = 0;
6
for (int k = 0; k < words.length; k++) {
7
if (words[k].length() > s.length()) {
8
continue;
9
}
10

11
while (i < words[k].length() && words[k].charAt(i) == s.charAt(j)) {
12
i++;
13
j++;
14
}
15
if (i == words[k].length()) {
16
count++;
17
}
18
i = 0;
19
j = 0;
20
}
21
return count;
22
}
23
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0