C# simple, readable

  • 0
    public class Solution 
        public bool IsSameTree(TreeNode p, TreeNode q)
            if (!IsNodeEqual(p, q)) return false;
            if (p == null && q == null) return true;
            if (!IsSameTree(p.left,  q.left))  return false;
            if (!IsSameTree(p.right, q.right)) return false;
            return true;
        public bool IsNodeEqual(TreeNode p, TreeNode q)
            if (p == null)
                return q == null;
            if (q == null)
                return p == null;
            return p.val == q.val;

Log in to reply

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