1ms java solution


  • 1
    M
    public boolean isSymmetric(TreeNode root) {
    	if (root == null) {
    		return true;
    	}
    	return fun(root.left, root.right);
    }
    
    public boolean fun(TreeNode l, TreeNode r) {
    	if (l == null && r == null) {
    		return true;
    	}
    	if (l != null && r == null) {
    		return false;
    	}
    	if (r != null && l == null) {
    		return false;
    	}
    	if(l.val != r.val){
    		return false;
    	}else{
    		return fun(l.left, r.right) && fun(l.right, r.left);
    	}
    }

Log in to reply
 

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