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