标签:
思路:递归。
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; } } }
标签:
原文地址:http://www.cnblogs.com/Machelsky/p/5858590.html