Skip to content

Commit 25919d9

Browse files
add 2744
1 parent dcf570b commit 25919d9

File tree

3 files changed

+56
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+56
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2760.java) | | Easy |
1515
| 2751 | [Robot Collisions](https://leetcode.com/problems/robot-collisions/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2751.java) | | Hard | Stack, Simulation
1616
| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2748.java) | | Easy |
17+
| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2744.java) | | Easy |
1718
| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2716.java) | [:tv:](https://youtu.be/aMJ3T0K8LjI) | Easy |
1819
| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2710.java) | | Easy |
1920
| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2706.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2744 {
4+
public static class Solution1 {
5+
public int maximumNumberOfStringPairs(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 (couldPair(words[i], words[j])) {
10+
pairs++;
11+
}
12+
}
13+
}
14+
return pairs;
15+
}
16+
17+
private boolean couldPair(String word1, String word2) {
18+
if (word1.length() != word2.length()) {
19+
return false;
20+
}
21+
int left = 0;
22+
int right = word1.length() - 1;
23+
while (left < right) {
24+
if (word1.charAt(left) != word2.charAt(right)) {
25+
return false;
26+
}
27+
left++;
28+
right--;
29+
}
30+
return word1.charAt(left) == word2.charAt(right);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2744;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _2744Test {
10+
private static _2744.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2744.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.maximumNumberOfStringPairs(new String[]{"cd", "ac", "dc", "ca", "zz"}));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)