Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.34 KB

_1460. Make Two Arrays Equal by Reversing Subarrays.md

File metadata and controls

56 lines (42 loc) · 1.34 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 04, 2024

Last updated : August 03, 2024


Related Topics : Array, Hash Table, Sorting

Acceptance Rate : 75.97 %


Solutions

C

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;
}

Python

class Solution:
    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
        return Counter(target) == Counter(arr)