Topic:
Given a sequence of two integers, the first sequence is the stack's press-in sequence, judging if the second is the stack's pop-up sequence? Suppose not to repeat, like 1,2,3,4,5 and 4,5,3,2,1.
Ideas:
- If the next pop-up number is just the top number of the Stack, it pops up. Not on the top of the stack, continuous press, know the pop-up number and the top of the stack, if the press is finished, not found, then return false.
Code:
Boolean Ispoporder (int[]Push,int[]Pop,int length) {Boolean possible = false;inti =0;intj =0; stack<integer> data = new stack<integer> (); while(J <length){ while(Data.empty () | | Data.top! =Pop[j]) {if(I >=length){ Break; } data.Push(Push. [i]); i++; }if(Data.top! =Pop[j]) { Break; } data.Pop(); j + +; }if(Data.empty () && J = =length) {possible = true; }returnpossible;}
-Amway A subscription number that summarizes the questions. Every day to push the classic face test and interview tips, are dry! Subscription number name: It face question summary subscription number QR Code is as follows:
"35" stack press-in Popup judgment