LeetCode 100 Same Tree
判断俩个二叉树是否完全相同。
此题要掌握树在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 bool IsSameTree(TreeNode p, TreeNode q)
{
if (p == null && q == null) return true;
if (p == null || q == null) return false;
if (p.val == q.val)
return IsSameTree(p.left, q.left) && IsSameTree(p.right, q.right);
return false;
}