auto commit
This commit is contained in:
@ -1433,7 +1433,8 @@ public boolean IsPopOrder(int[] pushSequence, int[] popSequence) {
|
||||
Stack<Integer> stack = new Stack<>();
|
||||
for (int pushIndex = 0, popIndex = 0; pushIndex < n; pushIndex++) {
|
||||
stack.push(pushSequence[pushIndex]);
|
||||
while (popIndex < n && stack.peek() == popSequence[popIndex]) {
|
||||
while (popIndex < n && !stack.isEmpty()
|
||||
&& stack.peek() == popSequence[popIndex]) {
|
||||
stack.pop();
|
||||
popIndex++;
|
||||
}
|
||||
@ -1578,7 +1579,7 @@ private boolean verify(int[] sequence, int first, int last) {
|
||||
int cutIndex = first;
|
||||
while (cutIndex < last && sequence[cutIndex] <= rootVal)
|
||||
cutIndex++;
|
||||
for (int i = cutIndex + 1; i < last; i++)
|
||||
for (int i = cutIndex; i < last; i++)
|
||||
if (sequence[i] < rootVal)
|
||||
return false;
|
||||
return verify(sequence, first, cutIndex - 1) && verify(sequence, cutIndex, last - 1);
|
||||
|
Reference in New Issue
Block a user