We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eee41de commit 938ea55Copy full SHA for 938ea55
same-tree/pmjuu.py
@@ -0,0 +1,21 @@
1
+'''
2
+시간 복잡도: O(n)
3
+공간 복잡도: O(n)
4
5
+from typing import Optional
6
+
7
+# Definition for a binary tree node.
8
+class TreeNode:
9
+ def __init__(self, val=0, left=None, right=None):
10
+ self.val = val
11
+ self.left = left
12
+ self.right = right
13
14
+class Solution:
15
+ def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
16
+ if not p and not q:
17
+ return True
18
+ if not p or not q:
19
+ return False
20
21
+ return p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
0 commit comments