auto commit

This commit is contained in:
CyC2018
2018-09-07 12:54:04 +08:00
parent 6ea965a9ef
commit f6e6808afe
15 changed files with 248 additions and 98 deletions

View File

@ -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);