From 94285e5fa415a98f20a0d4c440b82917a7096f91 Mon Sep 17 00:00:00 2001 From: Ching Date: Thu, 27 Jan 2022 20:16:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(leetcode):=20100.=E7=9B=B8=E5=90=8C?= =?UTF-8?q?=E7=9A=84=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 100.相同的树 Signed-off-by: Ching --- 100.相同的树.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 100.相同的树.py diff --git a/100.相同的树.py b/100.相同的树.py new file mode 100644 index 0000000..e2b7089 --- /dev/null +++ b/100.相同的树.py @@ -0,0 +1,29 @@ +# +# @lc app=leetcode.cn id=100 lang=python3 +# +# [100] 相同的树 +# + +# @lc code=start +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right + +from utils import * + + +class Solution: + def isSameTree(self, p: TreeNode, q: TreeNode) -> bool: + if not p and not q: + return True + if not p or not q: + return False + if p.val != q.val: + return False + return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) + + +# @lc code=end