Skip to content

Commit 2f7e848

Browse files
solves #2185: Counting Words With a Given Prefix in java
1 parent 0c3b894 commit 2f7e848

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@
715715
| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | |
716716
| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | |
717717
| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | |
718-
| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | |
718+
| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | |
719719
| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | | |
720720
| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | | |
721721
| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | | |
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class CountingWordsWithAGivenPrefix {
2+
public int prefixCount(String[] words, String prefix) {
3+
int count = 0;
4+
for (String word : words) {
5+
if (word.startsWith(prefix)) count++;
6+
}
7+
return count;
8+
}
9+
}

0 commit comments

Comments
 (0)