forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobzva.go
More file actions
38 lines (34 loc) Β· 752 Bytes
/
obzva.go
File metadata and controls
38 lines (34 loc) Β· 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
νμ΄
- μ¬κ·ν¨μλ₯Ό μ΄μ©ν΄μ νμ΄ν μ μμ΅λλ€
Big O
- N: νΈλ¦¬ λ
Έλμ κ°μ
- H: νΈλ¦¬μ λμ΄ (logN <= H <= N)
- Time complexity: O(N)
- λͺ¨λ λ
Έλλ₯Ό μ΅λ 1λ² νμν©λλ€
- Space complexity: O(H)
- μ¬κ· νΈμΆ μ€νμ κΉμ΄λ Hμ λΉλ‘νμ¬ μ¦κ°ν©λλ€
*/
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func isSameTree(p *TreeNode, q *TreeNode) bool {
// base case
if p == nil && q == nil {
return true
} else if p == nil || q == nil {
return false
}
if p.Val != q.Val {
return false
}
if !isSameTree(p.Left, q.Left) || !isSameTree(p.Right, q.Right) {
return false
}
return true
}