标签:style blog color div sp log c amp r
应用剑指offer
1 //判断二叉树是否平衡,后序遍历 2 bool isBalanced(treeNode* root,int& deep){ 3 if(root==NULL){ 4 deep=0; 5 return true; 6 } 7 //左右子树平衡时,根据高度差判断当前是否平衡 8 int lDeep,rDeep; 9 if(isBalanced(root->lChild,lDeep)&&isBalanced(root->rChild,rDeep)){ 10 if((lDeep-rDeep)<=1 || (rDeep-lDeep)<=1){ 11 deep=(lDeep>rDeep?lDeep:rDeep)+1; 12 return true; 13 } 14 } 15 return false; 16 }
标签:style blog color div sp log c amp r
原文地址:http://www.cnblogs.com/liuzhiminxd/p/3982973.html