Re: [閒聊] 每日leetcode

作者: smart0eddie (smart0eddie)   2024-08-03 22:13:13
2024-08-02
1460. Make Two Arrays Equal by Reversing Subarrays
You are given two integer arrays of equal length target and arr. In one step,
you can select any non-empty subarray of arr and reverse it. You are allowed
to make any number of steps.
Return true if you can make arr equal to target or false otherwise.
因為反轉不限次數 不限長度
所以實際上等同可以任意調整位置
那只要兩個有相同的元素就一定可以調出來
反正我們不用真的調出來
所以只需要比對兩個array的元素是不是都一樣
class Solution {
public:
bool canBeEqual(vector<int>& target, vector<int>& arr) {
vector<int> checkcount(1001);
for (int i = 0; i < target.size(); ++i) {
checkcount[target[i]]++;
checkcount[arr[i]]

Links booklink

Contact Us: admin [ a t ] ucptt.com