java: add «2185. Counting Words With a Given Prefix»
Refactor to stream. URL: https://leetcode.com/problems/counting-words-with-a-given-prefix/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
58f88d7db9
commit
b12e923384
1 changed files with 1 additions and 9 deletions
|
@ -1,13 +1,5 @@
|
|||
class Solution {
|
||||
public int prefixCount(String[] words, String pref) {
|
||||
var count = 0;
|
||||
|
||||
for (var word : words) {
|
||||
if (word.startsWith(pref)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
return (int) (Arrays.stream(words).filter(word -> word.startsWith(pref)).count());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue