首页 > 代码库 > 100. Same Tree

100. Same Tree

思路:递归。

null也是tree。

null tree

(definition)

Definition: (1) A tree which is empty. (2) A tree whose leaf nodes all have a null value.

 https://xlinux.nist.gov/dads/HTML/nulltree.html

 

public class Solution {    public boolean 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);        }        else        {            return false;        }            }}

 

100. Same Tree