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 edca7a0 commit bf8d1ffCopy full SHA for bf8d1ff
same-tree/sunjae95.js
@@ -0,0 +1,22 @@
1
+/**
2
+ * @description
3
+ * 두개의 트리를 동시에 순회한다를 초점으로 문제접근하여 풀이
4
+ *
5
+ * n = minimum tree node count of p or q
6
+ * time complexity: O(n)
7
+ * space complexity: O(1)
8
+ */
9
+var isSameTree = function (p, q) {
10
+ const preOrder = (tree1, tree2) => {
11
+ if (!tree1 && !tree2) return true;
12
+ if (!tree1 || !tree2) return false;
13
+
14
+ if (tree1.val !== tree2.val) return false;
15
+ if (!preOrder(tree1.left, tree2.left)) return false;
16
+ if (!preOrder(tree1.right, tree2.right)) return false;
17
18
+ return true;
19
+ };
20
21
+ return preOrder(p, q);
22
+};
0 commit comments