leetcode——100.相同的树

class Solution:
    def isSameTree(self, p, q) -> bool:
        if not p and not q:
            return True
        elif p is not None and q is not None:
            if p.val==q.val:
                return self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right)
            else:
                return False
        else:
            return False
执行用时 :40 ms, 在所有 Python3 提交中击败了95.91%的用户
内存消耗 :13.8 MB, 在所有 Python3 提交中击败了5.10%的用户
 
难过,我还是不知道它怎么输入的。。。。。
 
我现在好瞌睡。。。。
                                                                                                 ——2019.9.24
 
天呐,我之前都菜成什么样了。。。
public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p == null && q == null){
            return true;
        }else if(p == null || q == null){
            return false;
        }
        if(p.val != q.val){
            return false;
        }
        return isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }

人得慢慢进步,后悔这么久都没有做题。。

——2020.7.1

我的前方是万里征途,星辰大海!!
原文地址:https://www.cnblogs.com/taoyuxin/p/11579336.html