본문 바로가기
IT/알고리즘

36] Leetcode 1460. Make Two Arrays Equal by Reversing Sub-arrays

by 깻잎쌈 2020. 7. 21.
반응형

https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays/

 

Make Two Arrays Equal by Reversing Sub-arrays - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

두 배열을 구성하는 숫자가 다르면 무조건 false

숫자 개수가 다르거나, 없는 숫자가 있거나..

class Solution {
public:
    bool canBeEqual(vector<int>& target, vector<int>& arr) {
        bool fuck = false;
        
        for(int i = 0;i<arr.size();i++){
            fuck = false;
            for(int j = 0;j<target.size();j++){
                if(arr[i] == target[j]){
                    target[j] = -1;
                    fuck = true;
                    break;
                }
            }
            
            if(!fuck)
                return false;
        }
        
        return true; 
    }
};
반응형

댓글