# leetcode-TreeNode-go **Repository Path**: masx201/leetcode-TreeNode-go ## Basic Information - **Project Name**: leetcode-TreeNode-go - **Description**: https://github.com/egregors/TreeNode Binary Tree Node struct with LeetCode compatible Serialize / Deserialize functions - **Primary Language**: Go - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2024-11-25 - **Last Updated**: 2024-11-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TreeNode 🌲🌲🌲🌲 Binary Tree Node struct with LeetCode compatible Serialize / Deserialize format [![Build Status](https://github.com/egregors/TreeNode/actions/workflows/go.yml/badge.svg)](https://github.com/egregors/TreeNode/actions) thanks to https://github.com/egregors/TreeNode ## Install `go get github.com/masx200/leetcode-TreeNode-go` ## Usage https://pkg.go.dev/github.com/masx200/leetcode-TreeNode-go This package provides `TreeNode` data struct and a few function for serialization and deserialization respectively. ```go package main import ( "log" tn "github.com/masx200/leetcode-TreeNode-go" ) func main() { data := "[1,2,3,null,null,4,5]" root, err := tn.NewTreeNode(data) if err != nil { log.Fatal(err) } root.Right.Left.Val = 42 newData := root.String() ... } ``` A `NewTreeNode(data string) (*TreeNode, error)` constructor expect LeetCode style formatted string. Otherwise, to serialize a tree just call `String()` for `TreeNode` object. ## Benchmarks ```shell goos: darwin goarch: amd64 pkg: github.com/egregors/TreeNode cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz BenchmarkEmptyTree-12 13766786 77.96 ns/op Benchmark1_5Tree-12 2645138 448.3 ns/op ``` # Contributing Bug reports, bug fixes and new features are always welcome. Please open issues and submit pull requests for any new code.