#include<iostream>
#include<stack>
using namespace std;
int check(const int* a,const int* b,int len){
stack<int> v;
int i = 0,j = len-1;
while (i<len) {
if (b[i] == a[j]){
i++;
j--;
}
else if (!v.empty()&&(v.top() == a[j])) {
v.pop();
j--;
}
else{
v.push(b[i]);
i++;
}
}
return v.empty() ? 1 : 0;
}
int main() {
int a[] = { 1,2,3,4,5 };
int b[] = { 4,5,3,2,1 };
cout << (check(a,b,5)==1) << endl;
return 0;
}
剑指offer31
最新推荐文章于 2022-01-26 22:33:55 发布