Cattle off _ wins the title set offer - stack pressed into the pop-up sequence (java achieve)

Topic links:

https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106?tpId=13&tqId=11174&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking

Ideas: The code attempts to simulate the corresponding sequence of the stack, if fails, it returns false, otherwise true

 

Implementation code:

Package niuke; 

Import the java.util.Stack; 

public  class stack is pressed into the pop-up sequence {
     public  Boolean IsPopOrder ( int [] PUSHA, int [] POPA) { 
        Stack <Integer> = Stack new new Stack <> ();
         int I = 0 ;
         int J = 0 ; 
        stack.push (PUSHA [I ++ ]);
         the while (J <popA.length) { // simulated stack 
            the while (POPA [J] =! {stack.peek ())
                 IF ( == pushA.length I) return  to false;
                stack.push(pushA[i++]);
            }
            stack.pop();
            ++j;
        }
        return true;
    }
}

 

Code has been ac

I hope to be helpful

the above

Guess you like

Origin www.cnblogs.com/lavender-pansy/p/12441225.html
Recommended