Skip to content

Commit 4455551

Browse files
add 1460
1 parent 80ad4c8 commit 4455551

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1460|[Make Two Arrays Equal by Reversing Sub-arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1460.java) | |Easy|Array|
1112
|1457|[Pseudo-Palindromic Paths in a Binary Tree](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1457.java) | |Medium|Bit Manipulation, Tree, DFS|
1213
|1456|[Maximum Number of Vowels in a Substring of Given Length](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1456.java) | |Medium|String, Sliding Window|
1314
|1455|[Check If a Word Occurs As a Prefix of Any Word in a Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1455.java) | |Easy|String|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _1460 {
7+
public static class Solution1 {
8+
public boolean canBeEqual(int[] target, int[] arr) {
9+
Map<Integer, Integer> map = new HashMap<>();
10+
for (int num : target) {
11+
map.put(num, map.getOrDefault(num, 0) + 1);
12+
}
13+
for (int num : arr) {
14+
if (!map.containsKey(num)) {
15+
return false;
16+
} else {
17+
map.put(num, map.get(num) - 1);
18+
}
19+
}
20+
for (int key : map.keySet()) {
21+
if (map.get(key) != 0) {
22+
return false;
23+
}
24+
}
25+
return true;
26+
}
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1460;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1460Test {
10+
private static _1460.Solution1 solution1;
11+
private static int[] target;
12+
private static int[] arr;
13+
14+
@BeforeClass
15+
public static void setup() {
16+
solution1 = new _1460.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
target = new int[]{1, 2, 3, 4};
22+
arr = new int[]{2, 4, 1, 3};
23+
assertEquals(true, solution1.canBeEqual(target, arr));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)