Skip to content

Commit 02d680b

Browse files
committed
Add solution #2185
1 parent 0386cff commit 02d680b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@
372372
2114|[Maximum Number of Words Found in Sentences](./2114-maximum-number-of-words-found-in-sentences.js)|Easy|
373373
2129|[Capitalize the Title](./2129-capitalize-the-title.js)|Easy|
374374
2154|[Keep Multiplying Found Values by Two](./2154-keep-multiplying-found-values-by-two.js)|Easy|
375+
2185|[Counting Words With a Given Prefix](./2185-counting-words-with-a-given-prefix.js)|Easy|
375376
2215|[Find the Difference of Two Arrays](./2215-find-the-difference-of-two-arrays.js)|Easy|
376377
2235|[Add Two Integers](./2235-add-two-integers.js)|Easy|
377378
2244|[Minimum Rounds to Complete All Tasks](./2244-minimum-rounds-to-complete-all-tasks.js)|Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 2185. Counting Words With a Given Prefix
3+
* https://leetcode.com/problems/counting-words-with-a-given-prefix/
4+
* Difficulty: Easy
5+
*
6+
* You are given an array of strings words and a string pref.
7+
*
8+
* Return the number of strings in words that contain pref as a prefix.
9+
*
10+
* A prefix of a string s is any leading contiguous substring of s.
11+
*/
12+
13+
/**
14+
* @param {string[]} words
15+
* @param {string} pref
16+
* @return {number}
17+
*/
18+
var prefixCount = function(words, pref) {
19+
return words.filter(word => word.startsWith(pref)).length;
20+
};

0 commit comments

Comments
 (0)