比较简单的递归思路
对称的二叉树
http://www.nowcoder.com/questionTerminal/ff05d44dfdb04e1d83bdbdab320efbcb
boolean isSymmetrical(TreeNode pRoot) { if(pRoot==null) return true; TreeNode pLeft = pRoot.left; TreeNode pRight = pRoot.right; boolean res = help(pLeft,pRight); return res; } public boolean help(TreeNode pLeft,TreeNode pRight){ if(pLeft==null && pRight==null )return true; //下面是两种不对称的情况:一是左右节点一个为空一个不为空,二是左右节点值不想等 if(pLeft!=null&&pRight==null) return false; if(pLeft==null&&pRight!=null) return false; if(pLeft.val != pRight.val){ return false; }else{//递归去判断下面的情况 return help(pLeft.left,pRight.right)&& help(pLeft.right,pRight.left); } }