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 9eb2c85 commit 43f929cCopy full SHA for 43f929c
Moonjonghoo/tree/same_tree.js
@@ -0,0 +1,16 @@
1
+var isSameTree = function (p, q) {
2
+ // 두 노드가 모두 null인 경우
3
+ if (p === null && q === null) {
4
+ return true;
5
+ }
6
+ // 한 노드만 null인 경우
7
+ if (p === null || q === null) {
8
+ return false;
9
10
+ // 노드의 값이 다른 경우
11
+ if (p.val !== q.val) {
12
13
14
+ // 왼쪽 및 오른쪽 서브트리를 재귀적으로 비교
15
+ return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
16
+};
0 commit comments