Symmetric Tree
Symmetric Tree
问题:
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
思路:
dfs
我的代码:
public class Solution { public boolean isSymmetric(TreeNode root) { if(root == null) return true; return helper(root.left,root.right); } public boolean helper(TreeNode left, TreeNode right) { if(left == null && right == null) return true; if(left == null || right == null) return false; return left.val == right.val && helper(left.left, right.right) && helper(left.right, right.left); } }
posted on 2015-03-07 19:39 zhouzhou0615 阅读(110) 评论(0) 编辑 收藏 举报