-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtask.go
More file actions
37 lines (31 loc) · 638 Bytes
/
task.go
File metadata and controls
37 lines (31 loc) · 638 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
package main
import (
"fmt"
)
// Node
// TODO Comment it before submitting
type Node struct {
value int
left *Node
right *Node
}
func Solution(root *Node) bool {
if root.left == nil && root.right == nil {
return true
} else if root.left == nil || root.right == nil {
return false
}
return valueLR(root.left) == valueRL(root.right)
}
func valueLR(root *Node) string {
if root == nil {
return ""
}
return valueLR(root.left) + fmt.Sprint(root.value) + valueLR(root.right)
}
func valueRL(root *Node) string {
if root == nil {
return ""
}
return valueRL(root.right) + fmt.Sprint(root.value) + valueRL(root.left)
}