标签:div 判断 color tar empty 序列 order 平衡 平衡二叉树
1 bool verifyPostorder(vector<int>& postorder){ 2 if(postorder.empty()) return true; 3 bool res = helper(postorder,0,postorder.sizee()-1); 4 return res; 5 } 6 7 bool helper(vector<int>& postorder,int start,int end){ 8 if(postorder.empty() || start>end) return false; 9 10 int root = postorder[end]; 11 int i = start; 12 13 for(;i<end;i++){ 14 if(postorder[i]<root) 15 break; 16 } 17 for(int j = i;j<end;j++){ 18 if(postorder[j]<root) 19 return false; 20 } 21 bool left = true; 22 if(i>start)//是否有左子鼠 23 left = helper(postorder,start,i-1); 24 bool right = true; 25 if(i<end-1)//是否有柚子树 26 right = helper(postorder,i,end-1); 27 }
标签:div 判断 color tar empty 序列 order 平衡 平衡二叉树
原文地址:https://www.cnblogs.com/pengtangtang/p/12990242.html