思路:
遍历出栈序列,对于其中任一元素k,查看当前栈是否为空,若为空或栈顶元素不等于k,则根据入栈序列进行入栈,直至入栈序列中的元素k入栈。若直至入栈序列末尾仍无k,说明出栈序列错误。入栈完成后,将k出栈。
如上述操作,直至完成出栈序列遍历,说明出栈序列正确。
005203287
代码:

005521875

Move Zeroes

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For exa...

阅读全文

Odd Even Linked List

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not ...

阅读全文

Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space...

阅读全文