Accepted Java solution


  • 2
    W
    /**
     * 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)return true;
            
            TreeNode p=root, q=root;
            
            return check(root, root);
            
        }
        
        private boolean check(TreeNode l, TreeNode r){
            
            if(l == null && r !=null)return false;
            if(r == null && l !=null)return false;
            if(l == null && r == null)return true;
            
            if(l.val != r.val)return false;
            
            else return check(l.left, r.right) && check(l.right, r.left);
            
        }
    }

  • 0
    C

    waaaa, excellent solution!!!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.