/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/typeCodecstruct{}funcConstructor()Codec{returnCodec{}}// Serializes a tree to a single string.
func(this*Codec)serialize(root*TreeNode)string{ifroot==nil{return"-"}ret:=fmt.Sprintf("%d",root.Val)left,right:=this.serialize(root.Left),this.serialize(root.Right)ret+=fmt.Sprintf(",%s,%s",left,right)returnret}// Deserializes your encoded data to tree.
func(this*Codec)deserialize(datastring)*TreeNode{path:=strings.Split(data,",")i:=0varbuildTreefunc()*TreeNodebuildTree=func()*TreeNode{num,err:=strconv.Atoi(path[i])i++iferr!=nil{returnnil}root:=&TreeNode{Val:num}root.Left=buildTree()root.Right=buildTree()returnroot}returnbuildTree()}/**
* Your Codec object will be instantiated and called as such:
* ser := Constructor()
* deser := Constructor()
* tree := ser.serialize(root)
* ans := deser.deserialize(tree)2
* return ans
*/