| 3 | |
| 4 | //Double map solution |
| 5 | class Solution { |
| 6 | public boolean canBeEqual(int[] target, int[] arr) { |
| 7 | HashMap<Integer,Integer> map1 = new HashMap<>(); |
| 8 | for(int element : target){ |
| 9 | map1.put(element, map1.getOrDefault(element,0)+1); |
| 10 | } |
| 11 | |
| 12 | HashMap<Integer,Integer> map2 = new HashMap<>(); |
| 13 | for(int element : arr){ |
| 14 | map2.put(element, map2.getOrDefault(element,0)+1); |
| 15 | } |
| 16 | |
| 17 | for(int key : map1.keySet()){ |
| 18 | if(!map2.containsKey(key)){ |
| 19 | return false; |
| 20 | } |
| 21 | if(map1.get(key)!=map2.get(key)){ |
| 22 | return false; |
| 23 | } |
| 24 | } |
| 25 | return true; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | //single map solution |
| 30 | class Solution { |
nothing calls this directly
no outgoing calls
no test coverage detected