Java 2 lines solution (1ms)


  • -1
       public boolean isSymmetric(TreeNode root){
    		return (root==null)?true:helper(root.left,root.right);
    	}
    	private boolean helper(TreeNode p,TreeNode q){
    		return (p==null||q==null)?p==q:(p.val==q.val)&&helper(p.right,q.left)&&helper(p.left,q.right);
    	}

Log in to reply
 

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