标签:输入 style roo off enc tle sub root esc
1 class Solution { 2 public: 3 bool VerifySquenceOfBST(vector<int> sequence) { 4 if (sequence.size() == 0)return false; 5 return isBST(sequence, 0, sequence.size() - 1); 6 } 7 bool isBST(vector<int>v, int L, int R) 8 { 9 if (L >= R)return true; 10 int root = v[R]; 11 int i = L; 12 while (v[i] < root)++i;//找到左子树 13 int j = i; 14 while (j < R)if (v[j++] < root)return false;//判断右子树 15 return isBST(v, L, i - 1) && isBST(v, i, R - 1); 16 } 17 };
标签:输入 style roo off enc tle sub root esc
原文地址:https://www.cnblogs.com/zzw1024/p/11681930.html