leetcode-101. Symmetric Tree
2016-12-26 10:13
351 查看
leetcode-101. Symmetric Tree
题目:>
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
1
/ \
2 2
/ \ / \
3 4 4 3
But the following [1,2,2,null,3,null,3] is not:
1
/ \
2 2
\ \
3 3
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public boolean isSymmetric(TreeNode root) { if(root == null) return true; return helper(root.left,root.right); } private boolean helper(TreeNode left, TreeNode right){ if(left==null && right ==null)return true; if(left == null || right ==null || left.val!=right.val) return false; return helper(left.left,right.right) && helper(left.right,right.left); } }
相关文章推荐
- LeetCode解题报告 101. Symmetric Tree [easy]
- leetcode 101. Symmetric Tree
- 【LeetCode】101. Symmetric Tree
- LeetCode101. Symmetric Tree
- LeetCode 101. Symmetric Tree
- leetcode 101. Symmetric Tree
- LeetCode 101. Symmetric Tree
- leetcode101. Symmetric Tree
- leetcode 每日一题 101. Symmetric Tree
- 小白笔记---------------------------------leetcode(101. Symmetric Tree )
- Leetcode-标签为Tree 101. Symmetric Tree
- Leetcode 101. Symmetric Tree
- leetcode 101. Symmetric Tree
- LeetCode 101. Symmetric Tree
- 第三周:[LeetCode]101. Symmetric Tree
- LeetCode-101. Symmetric Tree-using C
- 【LeetCode】101. Symmetric Tree-对称树/镜像树
- [Leetcode] 101. Symmetric Tree
- 【leetcode】101. Symmetric Tree【java】递归和非递归两种方法
- LeetCode-101. Symmetric Tree