Skip to content

Commit b8610a4

Browse files
refactor 336
1 parent 74f1d68 commit b8610a4

File tree

1 file changed

+2
-15
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-15
lines changed

src/main/java/com/fishercoder/solutions/_336.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
import java.util.List;
77
import java.util.Map;
88

9-
/**336. Palindrome Pairs
10-
*
11-
* Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.
12-
13-
Example 1:
14-
Given words = ["bat", "tab", "cat"]
15-
Return [[0, 1], [1, 0]]
16-
The palindromes are ["battab", "tabbat"]
17-
Example 2:
18-
Given words = ["abcd", "dcba", "lls", "s", "sssll"]
19-
Return [[0, 1], [1, 0], [3, 2], [2, 4]]
20-
The palindromes are ["dcbaabcd", "abcddcba", "slls", "llssssll"]
21-
*/
229
public class _336 {
2310

2411
public static class Solution1 {
@@ -36,9 +23,9 @@ public List<List<Integer>> palindromePairs(String[] words) {
3623
String s = words[i].substring(l, r);
3724
Integer j = map.get(new StringBuilder(s).reverse().toString());
3825
if (j != null && j != i && isPalindrome(
39-
words[i].substring(l == 0 ? r : 0, l == 0 ? words[i].length() : l))) {
26+
words[i].substring(l == 0 ? r : 0, l == 0 ? words[i].length() : l))) {
4027
pairs.add(
41-
Arrays.asList(l == 0 ? new Integer[] {i, j} : new Integer[] {j, i}));
28+
Arrays.asList(l == 0 ? new Integer[]{i, j} : new Integer[]{j, i}));
4229
}
4330
if (r < words[i].length()) {
4431
r++;

0 commit comments

Comments
 (0)