[算法与数据结构][array operations][leetcode1460:easy]Make Two Arrays Equal by Reversing Sub-arrays

this problem shows that
what if you dont know the level is easy?
could you reduce this problem into this?
or just doing something brute force.

This is a very important problem to me,
it includes confidence.

this problem deserve a summary for solving thinking path

my code

class Solution {
public:
    bool canBeEqual(vector<int>& target, vector<int>& arr) {
        sort(target.begin(), target.end());
        sort(arr.begin(), arr.end());
        for(int i=0;i<arr.size();i++){
            if(arr[i] != target[i]){
                return false;
            }
        }
        return true;
    }
};

nice piece

static auto speedup = [](){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    return 0;
}();

class Solution {
public:
    bool canBeEqual(vector<int>& target, vector<int>& arr) {
        vector<int> v(1001, 0), v1(1001,0);
        for(auto a : target) v[a]++;
        for(auto a : arr) v1[a]++;
        
        return v==v1;
    }
};

你可能感兴趣的:(算法和数据结构)