Make Two Arrays Equal by Reversing Sub-arrays LeetCode solution in Java

1
class Solution {
2
public boolean canBeEqual(int[] target, int[] arr) {
3
HashMap<Integer, Integer> hm1 = new HashMap();
4
for (int i : arr) {
5
if (hm1.containsKey(i)) hm1.put(i, hm1.get(i) + 1);
6
else hm1.put(i, 1);
7
}
8
for (int i : target) {
9
if (hm1.containsKey(i)) {
10
hm1.put(i, hm1.getOrDefault(i, 0) - 1);
11
if (hm1.get(i) == 0) hm1.remove(i);
12
} else return false;
13
}
14
if (hm1.size() == 0) return true;
15

16
return false;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0