forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1460.java
28 lines (26 loc) · 786 Bytes
/
_1460.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _1460 {
public static class Solution1 {
public boolean canBeEqual(int[] target, int[] arr) {
Map<Integer, Integer> map = new HashMap<>();
for (int num : target) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
for (int num : arr) {
if (!map.containsKey(num)) {
return false;
} else {
map.put(num, map.get(num) - 1);
}
}
for (int key : map.keySet()) {
if (map.get(key) != 0) {
return false;
}
}
return true;
}
}
}