MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / deserialize

Method deserialize

tasks/449.go:43–61  ·  view source on GitHub ↗

Deserializes your encoded data to tree.

(data string)

Source from the content-addressed store, hash-verified

41
42// Deserializes your encoded data to tree.
43func (this *Codec) deserialize(data string) *TreeNode {
44 index := -1
45 arr := strings.Split(data, ",")
46 var dfs func() *TreeNode
47 dfs = func() *TreeNode {
48 index++
49 if index >= len(data) || arr[index] == "x" {
50
51 return nil
52 }
53 val, _ := strconv.Atoi(arr[index])
54
55 head := &TreeNode{Val: val}
56 head.Left = dfs()
57 head.Right = dfs()
58 return head
59 }
60 return dfs()
61}

Callers

nothing calls this directly

Calls 1

dfsFunction · 0.70

Tested by

no test coverage detected