-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2744.java
33 lines (31 loc) · 1022 Bytes
/
_2744.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
25
26
27
28
29
30
31
32
33
package com.fishercoder.solutions.thirdthousand;
public class _2744 {
public static class Solution1 {
public int maximumNumberOfStringPairs(String[] words) {
int pairs = 0;
for (int i = 0; i < words.length - 1; i++) {
for (int j = i + 1; j < words.length; j++) {
if (couldPair(words[i], words[j])) {
pairs++;
}
}
}
return pairs;
}
private boolean couldPair(String word1, String word2) {
if (word1.length() != word2.length()) {
return false;
}
int left = 0;
int right = word1.length() - 1;
while (left < right) {
if (word1.charAt(left) != word2.charAt(right)) {
return false;
}
left++;
right--;
}
return word1.charAt(left) == word2.charAt(right);
}
}
}