```package main
import "strconv"
import "strings"
import . "nc_tools"
/*
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* @param root TreeNode类
* @return TreeNode类
*/
func Serialize(root *TreeNode) string {
if root == nil {
return "#"
}
return strconv.Itoa(root.Val) + "," + Serialize(root.Left) + "," + Serialize(root.Right)
}
func Deserialize(s string) *TreeNode {
str := strings.Split(s, ",")
return buildTree(&str)
}
func buildTree(s *[]string) *TreeNode {
rootValue := (*s)[0]
*s = (*s)[1:]
if rootValue == "#" {
return nil
}
val, _ := strconv.Atoi(rootValue)
root := &TreeNode{
Val: val,
Left: nil,
Right: nil,
}
root.Left = buildTree(s)
root.Right = buildTree(s)
return root
}