All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 04, 2024
Last updated : August 03, 2024
Related Topics : Array, Hash Table, Sorting
Acceptance Rate : 75.97 %
int compareHelper(const void* one, const void* two) {
return *((int *) one) - *((int *) two);
}
bool canBeEqual(int* target, int targetSize, int* arr, int arrSize) {
if (!(targetSize == arrSize)) {
return false;
}
qsort(arr, arrSize, sizeof(int), compareHelper);
qsort(target, targetSize, sizeof(int), compareHelper);
for (int i = 0; i < arrSize; i++) {
if (!(arr[i] == target[i])) {
return false;
}
}
return true;
}
class Solution:
def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
return Counter(target) == Counter(arr)