Skip to content

Commit 8a7990d

Browse files
add 2839
1 parent 41e35d3 commit 8a7990d

File tree

3 files changed

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

3 files changed

+76
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| 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 |
88
| 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 |
99
| 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
10+
| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2839.java) | | Easy |
1011
| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2833.java) | | Easy |
1112
| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2828.java) | | Easy |
1213
| 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 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.Arrays;
4+
5+
public class _2839 {
6+
public static class Solution1 {
7+
/**
8+
* Only a total of 6 possibilities, try them all.
9+
*/
10+
public boolean canBeEqual(String s1, String s2) {
11+
if (s1.equals(s2)) {
12+
return true;
13+
}
14+
char[] c1 = s1.toCharArray();
15+
char[] c2 = s2.toCharArray();
16+
for (int i = 0; i < 2; i++) {
17+
swap(c1, i);
18+
if (Arrays.equals(c1, c2)) {
19+
return true;
20+
}
21+
}
22+
c1 = s1.toCharArray();
23+
c2 = s2.toCharArray();
24+
//swap only (1,3) for c1 now
25+
swap(c1, 1);
26+
if (Arrays.equals(c1, c2)) {
27+
return true;
28+
}
29+
30+
c1 = s1.toCharArray();
31+
c2 = s2.toCharArray();
32+
for (int i = 0; i < 2; i++) {
33+
swap(c2, i);
34+
if (Arrays.equals(c1, c2)) {
35+
return true;
36+
}
37+
}
38+
c1 = s1.toCharArray();
39+
c2 = s2.toCharArray();
40+
//swap only (1,3) for c2 now
41+
swap(c2, 1);
42+
if (Arrays.equals(c1, c2)) {
43+
return true;
44+
}
45+
return false;
46+
}
47+
48+
private void swap(char[] c, int i) {
49+
char tmp = c[i];
50+
c[i] = c[i + 2];
51+
c[i + 2] = tmp;
52+
}
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2839;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
9+
public class _2839Test {
10+
private static _2839.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2839.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertTrue(solution1.canBeEqual("bnxw", "bwxn"));
20+
}
21+
}

0 commit comments

Comments
 (0)