<> Title Description

Enter two Integer Sequences , The first sequence represents the push order of the stack , Please judge whether the second sequence is the pop-up sequence of the stack . Assume that all the numbers of the push stack are not equal .

<> Example

For example, sequence 1,2,3,4,5 Is the push order of a stack , sequence 4,5,3,2,1 Is a pop-up sequence corresponding to the stack pressing sequence , but 4,3,5,1,2 It can't be the pop-up sequence of the stack pressing sequence .( be careful : The length of these two sequences is equal )

<> Solutions to problems

In this paper, we only need to use an auxiliary stack to simulate the push and pop of the stack , If two sequences can be successfully executed , We can prove that the pop-up sequence corresponds to the press in sequence .

function IsPopOrder(pushV, popV) { // write code here if(pushV.length==0)
return true; let stack=[]; let t=0; for(let i=0;i<pushV.length;i++){ stack.push(
pushV[i]); while(stack.length&&stack[stack.length-1]==popV[t]){ t++; stack.pop()
; } } return stack.length==0; }
Operating environment :JavaScript (V8 6.0.0)
Running time :14ms
Occupied memory :5324k

©2019-2020 Toolsou All rights reserved,
First knowledge python Skills summary GDOI2019 travels c Linguistic 5 Three common sorting methods Python Basic knowledge and notes " Cephalosporin wine Say go and go "? DANGER ! Don't drink alcohol when taking these drugs Thorough explanation from Zhongtai vue The component page height is adaptive according to the screen size Classical algorithm - recursion ( The case of raw rabbit ) Big data tells you , How tired are Chinese women about keras use fit_generator Encountered in StopIteration