- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3042.java
24 lines (22 loc) · 756 Bytes
/
_3042.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
packagecom.fishercoder.solutions.fourththousand;
publicclass_3042 {
publicstaticclassSolution1 {
publicintcountPrefixSuffixPairs(String[] words) {
intpairs = 0;
for (inti = 0; i < words.length - 1; i++) {
for (intj = i + 1; j < words.length; j++) {
if (isPrefixAndSuffix(words[i], words[j])) {
pairs++;
}
}
}
returnpairs;
}
privatebooleanisPrefixAndSuffix(Stringword1, Stringword2) {
if (word1.length() > word2.length()) {
returnfalse;
}
returnword2.startsWith(word1) && word2.endsWith(word1);
}
}
}