leetcodetreenode-leetcode:leetcode算法题,go语言

时间:2024-07-21 03:00:21
【文件属性】:

文件名称:leetcodetreenode-leetcode:leetcode算法题,go语言

文件大小:344KB

文件格式:ZIP

更新时间:2024-07-21 03:00:21

系统开源

leetcode 树节点leetcode leetcode 算法题,去语言 力扣串生成二叉树代码 type TreeNode struct { Val int Left *TreeNode Right *TreeNode } func generateTree(str string) (root *TreeNode) { s := strings.TrimLeft(str, "[") s = strings.TrimRight(s, "]") arr := strings.Split(s, ",") if len(arr) == 0 || arr[0] == "null" { return } root = new(TreeNode) root.Val, _ = strconv.Atoi(arr[0]) arr = arr[1:] queue := []*TreeNode{root} for len(queue) > 0 && len(arr) > 0 { node := queue[0] queue = queue[1:] if arr[0]


网友评论