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 1ef9a64 commit 424cc78Copy full SHA for 424cc78
same-tree/uraflower.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
10
+ * @param {TreeNode} p
11
+ * @param {TreeNode} q
12
+ * @return {boolean}
13
14
+const isSameTree = function(p, q) {
15
+ if (!p && !q) return true;
16
+ return p?.val === q?.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
17
+};
18
+
19
+// 시간복잡도: O(n)
20
+// 공간복잡도: O(h) (h: 트리의 높이, 즉 재귀 호출 스택)
0 commit comments