
今天我们一起刷题。皮皮猪安静的坐我旁边。很惬意。很心安。
又有点紧张,万一做不出来怪丢人的。
幸好都做出来了。
帅。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
class { public: bool VerifySquenceOfBST(vector<int> sequence) { if (sequence.size() == 1)return true; vector<int> left; vector<int> right; int root = sequence[sequence.size() - 1]; bool tag = true; for (int i = 0; i<sequence.size() - 1; i++){ if (sequence[i]<root && tag){ left.push_back(sequence[i]); continue; } tag = false; if (sequence[i]>root && !tag){ right.push_back(sequence[i]); continue; } return false; } return VerifySquenceOfBST(left) && VerifySquenceOfBST(right); } };
|
近期评论