bool validateStackSequences(int* pushed, int pushedSize, int* popped, int poppedSize) {
int top=0;
int i,j,flag=1;
i=j=0;
int *stack=malloc(sizeof(int)*(pushedSize+2));
stack[0]=0;
while(i<poppedSize)
{
while(top==0||stack[top]!=popped[j]&&i<poppedSize)
{
stack[++top]=pushed[i++];
}
while(top!=0&&j<poppedSize&&stack[top]==popped[j])
{
top--;
j++;
}
}
if(j==poppedSize)
return 1;
else
return 0;
}
946. Validate Stack Sequences C语言 fasater than 100%
最新推荐文章于 2022-06-14 10:23:51 发布