Update the algorithm for 二叉搜索树的后序遍历序列

This commit is contained in:
Stanton 2018-07-05 15:46:43 -07:00 committed by GitHub
parent d51971aa50
commit 633aada3fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1532,10 +1532,10 @@ private boolean verify(int[] sequence, int first, int last)
return true;
int rootVal = sequence[last];
int cutIndex = first;
while (cutIndex < last && sequence[cutIndex] <= rootVal)
while (cutIndex < last && sequence[cutIndex] > rootVal)
cutIndex++;
for (int i = cutIndex + 1; i < last; i++)
if (sequence[i] < rootVal)
if (sequence[i] > rootVal)
return false;
return verify(sequence, first, cutIndex - 1) && verify(sequence, cutIndex, last - 1);
}