标签:leetcode
https://oj.leetcode.com/problems/symmetric-tree/
http://blog.csdn.net/linhuanmars/article/details/23072829
/** * Definition for binary tree * 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 || (root.left == null && root.right == null)) return true; return help(root.left, root.right); } // DFS private boolean help(TreeNode l, TreeNode r) { if (l == null && r == null) return true; if (l == null && r != null) return false; if (l != null && r == null) return false; return (l.val == r.val) && help(l.left, r.right) && help(l.right, r.left); } }
标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1599583