File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ ํ์ด
3+ - ์ฌ๊ทํจ์๋ฅผ ์ด์ฉํด์ ํ์ดํ ์ ์์ต๋๋ค
4+ Big O
5+ - N: ํธ๋ฆฌ ๋
ธ๋์ ๊ฐ์
6+ - H: ํธ๋ฆฌ์ ๋์ด (logN <= H <= N)
7+ - Time complexity: O(N)
8+ - ๋ชจ๋ ๋
ธ๋๋ฅผ ์ต๋ 1๋ฒ ํ์ํฉ๋๋ค
9+ - Space complexity: O(H)
10+ - ์ฌ๊ท ํธ์ถ ์คํ์ ๊น์ด๋ H์ ๋น๋กํ์ฌ ์ฆ๊ฐํฉ๋๋ค
11+ */
12+
13+ /**
14+ * Definition for a binary tree node.
15+ * type TreeNode struct {
16+ * Val int
17+ * Left *TreeNode
18+ * Right *TreeNode
19+ * }
20+ */
21+ func isSameTree (p * TreeNode , q * TreeNode ) bool {
22+ // base case
23+ if p == nil && q == nil {
24+ return true
25+ } else if p == nil || q == nil {
26+ return false
27+ }
28+
29+ if p .Val != q .Val {
30+ return false
31+ }
32+
33+ if ! isSameTree (p .Left , q .Left ) || ! isSameTree (p .Right , q .Right ) {
34+ return false
35+ }
36+
37+ return true
38+ }
You canโt perform that action at this time.
0 commit comments