标签:后序 ceo 重要 ack turn ++ bst sequence 应该
其中,最重要的是,sequence一开始如果它的值为空的话,它是要返回false。但是之后,只要sizex小于3都应该返回true
class Solution {
public:
bool VerifySquenceOfBST(vector<int> sequence) {
if (sequence.size() == 0)
{
return false;
}
return VerifySquenceOfBSTChild(sequence);
}
bool VerifySquenceOfBSTChild(vector<int> sequence)
{
if (sequence.size() < 3)
{
return true;
}
int temp = sequence[sequence.size() - 1];
vector<int> littlerVec;
vector<int> biggerVec;
int i = 0;
for (; i < sequence.size() - 1; i++)
{
if (sequence[i] < temp)
{
littlerVec.push_back(sequence[i]);
} else {
break;
}
}
for (; i < sequence.size() - 1; i++)
{
if (sequence[i] > temp)
{
biggerVec.push_back(sequence[i]);
} else {
return false;
}
}
return (VerifySquenceOfBSTChild(littlerVec) && VerifySquenceOfBSTChild(biggerVec));
}
};
标签:后序 ceo 重要 ack turn ++ bst sequence 应该
原文地址:http://www.cnblogs.com/adamhome/p/7538827.html