标签:后序遍历 bst vector last 遍历 span ack return bsp
class Solution { public: bool VerifySquenceOfBST(vector<int> sequence) { vector<int> right; vector<int> left; int size = sequence.size(); int last = sequence[size - 1]; if (size== 0) { return false; } //left int mid = 0; for (int i = 0; i<(size); ++i) { if (sequence[i] < last) { left.push_back(sequence[i]); ++mid; } else break; } //right for (int j = mid; j < (size-1); ++j) { if (sequence[j]>last) { right.push_back(sequence[j]); } else { return false; break; } } bool leftresult=true; bool rightresult=true; if (!left.empty()) { bool leftresult = VerifySquenceOfBST(left); } if (!right.empty()) { bool rightresult = VerifySquenceOfBST(right); } return(leftresult&&rightresult); } };
标签:后序遍历 bst vector last 遍历 span ack return bsp
原文地址:http://www.cnblogs.com/159269lzm/p/7295588.html