8000 add 3042 · nayakmk/LeetcodeSolutions@0a4b323 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a4b323

Browse files
add 3042
1 parent af69586 commit 0a4b323

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 3042 |[Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3042.java) | | Easy |
1112
| 3038 |[Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3038.java) | | Easy |
1213
| 3006 |[Find Beautiful Indices in the Given Array I](https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3006.java) | | Medium |
1314
| 3005 |[Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3005.java) | | Easy |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _3042 {
4+
public static class Solution1 {
5+
public int countPrefixSuffixPairs(String[] words) {
6+
int pairs = 0;
7+
for (int i = 0; i < words.length - 1; i++) {
8+
for (int j = i + 1; j < words.length; j++) {
9+
if (isPrefixAndSuffix(words[i], words[j])) {
10+
pairs++;
11+
}
12+
}
13+
}
14+
return pairs;
15+
}
16+
17+
private boolean isPrefixAndSuffix(String word1, String word2) {
18+
if (word1.length() > word2.length()) {
19+
return false;
20+
}
21+
return word2.startsWith(word1) && word2.endsWith(word1);
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)
0