二叉树101、对称二叉树

    技术2022-07-10  133

    题目

    C#代码

    /** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * public TreeNode(int x) { val = x; } * } */ public class Solution { public bool IsSymmetric(TreeNode root) { if(root==null) return true; return IsMirror(root.left,root.right); } private bool IsMirror(TreeNode l,TreeNode r) { if(l==null&&r==null) return true; if((l==null&&r!=null)||(l!=null&&r==null)||l.val!=r.val) return false; return IsMirror(l.left,r.right)&&IsMirror(l.right,r.left); } }
    Processed: 0.014, SQL: 12