Skip to content

Commit 960eb00

Browse files
add 2937
1 parent 54b14af commit 960eb00

File tree

3 files changed

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

3 files changed

+61
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
| 2970 | [Count the Number of Incremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2970.java) | | Easy |
55
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2965.java) | | Easy |
66
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2942.java) | | Easy |
7+
| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2937.java) | | Easy |
78
| 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2864.java) | | Easy |Greedy
89
| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2824.java) | | Easy |
910
| 2812 | [Find the Safest Path in a Grid](https://leetcode.com/problems/find-the-safest-path-in-a-grid/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2812.java) | | Medium |BFS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2937 {
4+
public static class Solution1 {
5+
public int findMinimumOperations(String s1, String s2, String s3) {
6+
if (s1.charAt(0) != s2.charAt(0) || s1.charAt(0) != s3.charAt(0) || s2.charAt(0) != s3.charAt(0)) {
7+
return -1;
8+
}
9+
int minOps = 0;
10+
int minLen = Math.min(s1.length(), Math.min(s2.length(), s3.length()));
11+
int i = 1, j = 1, k = 1;
12+
for (; i < minLen && j < minLen && k < minLen; i++, j++, k++) {
13+
if (s1.charAt(i) != s2.charAt(j) || s2.charAt(j) != s3.charAt(k)) {
14+
minOps += s1.length() - i;
15+
minOps += s2.length() - j;
16+
minOps += s3.length() - k;
17+
i = s1.length();
18+
j = s2.length();
19+
k = s3.length();
20+
break;
21+
}
22+
}
23+
minOps += s1.length() - i;
24+
minOps += s2.length() - j;
25+
minOps += s3.length() - k;
26+
return minOps;
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2937;
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 _2937Test {
10+
private static _2937.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2937.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.findMinimumOperations("abc", "abb", "ab"));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(3, solution1.findMinimumOperations("a", "aabc", "a"));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(7, solution1.findMinimumOperations("ca", "cccabb", "cb"));
30+
}
31+
}

0 commit comments

Comments
 (0)