Skip to content

Commit 18b6658

Browse files
committedMay 27, 2023
solves #2255: Count Prefixes of a Given String
in java
1 parent 1870f7a commit 18b6658

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
 

‎README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@
730730
| 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | |
731731
| 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | |
732732
| 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | |
733-
| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | |
734-
| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | | |
733+
| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | |
734+
| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | |
735735
| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | | |
736736
| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | | |
737737
| 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | | |

‎src/CountPrefixesOfAGivenString.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// https://leetcode.com/problems/count-prefixes-of-a-given-string
2+
// T: O(|words| * |s|)
3+
// S: O(1)
4+
5+
public class CountPrefixesOfAGivenString {
6+
public int countPrefixes(String[] words, String s) {
7+
int result = 0;
8+
for (String word : words) {
9+
if (s.startsWith(word)) result++;
10+
}
11+
return result;
12+
}
13+
}

0 commit comments

Comments
 (0)
Please sign in to comment.