1460. Make Two Arrays Equal by Reversing Subarrays
JAVA
class Solution {
public boolean canBeEqual(int[] target, int[] arr) {
Arrays.sort(target);
Arrays.sort(arr);
return Arrays.equals(target, arr);
}
}C++
class Solution {
public:
bool canBeEqual(vector<int>& B, vector<int>& A) {
unordered_map<int, int> cnt;
for (int n : A) cnt[n]++;
for (int n : B) {
if (--cnt[n] < 0) return false;
}
return true;
}
};
Comments
Post a Comment