{"id":13413807,"url":"https://github.com/sbourlon/go-lctree","last_synced_at":"2025-03-14T20:30:39.038Z","repository":{"id":94710046,"uuid":"261089875","full_name":"sbourlon/go-lctree","owner":"sbourlon","description":"go-lctree provides a CLI and Go primitives to serialize and deserialize LeetCode binary trees (e.g. \"[5,4,7,3,null,2,null,-1,null,9]\").","archived":false,"fork":false,"pushed_at":"2020-06-03T21:19:42.000Z","size":1736,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T09:17:44.664Z","etag":null,"topics":["leetcode","leetcode-golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbourlon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-05-04T05:39:46.000Z","updated_at":"2024-02-02T19:31:54.000Z","dependencies_parsed_at":"2023-04-13T17:36:16.588Z","dependency_job_id":null,"html_url":"https://github.com/sbourlon/go-lctree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbourlon%2Fgo-lctree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbourlon%2Fgo-lctree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbourlon%2Fgo-lctree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbourlon%2Fgo-lctree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbourlon","download_url":"https://codeload.github.com/sbourlon/go-lctree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243641954,"owners_count":20323940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["leetcode","leetcode-golang"],"created_at":"2024-07-30T20:01:49.863Z","updated_at":"2025-03-14T20:30:38.570Z","avatar_url":"https://github.com/sbourlon.png","language":"Go","funding_links":[],"categories":["Serialization","序列化","安全领域相关库","Relational Databases"],"sub_categories":["HTTP Clients","HTTP客户端","查询语"],"readme":"\u003cdiv align=\"center\"\u003e\n\n# lctree :seedling:\n\nlctree provides a CLI and Golang primitives to serialize and deserialize [LeetCode binary trees](https://support.leetcode.com/hc/en-us/articles/360011883654-What-does-1-null-2-3-mean-in-binary-tree-representation) (e.g. \"[5,4,7,3,null,2,null,-1,null,9]\").\n\n[Overview](#overview)\u0026nbsp;\u0026nbsp;\u0026nbsp;|\u0026nbsp;\u0026nbsp;\u0026nbsp;[Getting Started](#getting-started)\u0026nbsp;\u0026nbsp;\u0026nbsp;|\u0026nbsp;\u0026nbsp;\u0026nbsp;[Contributing](#contributing)\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\n[![API reference](https://img.shields.io/badge/godoc-reference-5272B4)](https://pkg.go.dev/github.com/sbourlon/go-lctree?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/sbourlon/go-lctree)](https://goreportcard.com/report/github.com/sbourlon/go-lctree) [![Coverage Status](https://coveralls.io/repos/github/sbourlon/go-lctree/badge.svg?branch=master)](https://coveralls.io/github/sbourlon/go-lctree?branch=master) [![Build Status](https://travis-ci.org/sbourlon/go-lctree.svg?branch=master)](https://travis-ci.org/sbourlon/go-lctree)\n\n\u003c/div\u003e\n\n## Overview\n- Deserialize/Serialize\n- Walk Depth-First\n- Walk Breadth-First\n- Convert to [DOT language](https://graphviz.gitlab.io/_pages/doc/info/lang.html) for visualization\n- CLI (see [bin/](bin/))\n\n## Getting Started\n### Deserialize\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sbourlon/go-lctree\"\n)\n\n// Type alias\ntype TreeNode = lctree.TreeNode\n\nfunc mySolution(root *TreeNode) {\n\tfmt.Printf(\"root: %+v\\n\", root)\n\treturn\n}\n\nfunc main() {\n\ttree := lctree.Deserialize(\"[1,null,2,3]\")\n\tmySolution(tree)\n}\n```\nOutput:\n```\nroot: \u0026{Val:1 Left:\u003cnil\u003e Right:0xc00008e020}\n```\n\n### Serialize\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sbourlon/go-lctree\"\n)\n\ntype TreeNode = lctree.TreeNode\n\nfunc mySolution() *TreeNode {\n\treturn lctree.Deserialize(\"[1,null,2,3]\")\n}\n\nfunc main() {\n\ttree := mySolution()\n\tfmt.Println(lctree.Serialize(tree))\n}\n```\nOutput:\n```\n[1,null,2,3]\n```\n\n### Walk Depth-First\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sbourlon/go-lctree\"\n)\n\ntype TreeNode = lctree.TreeNode\n\nfunc mySolution() *TreeNode {\n\treturn lctree.Deserialize(\"[1,null,2,3]\")\n}\n\nfunc main() {\n\ttree := mySolution()\n\n\twalkFn := func(n *TreeNode) error {\n\t\tfmt.Printf(\"%+v\\n\", n)\n\t\treturn nil\n\t}\n\n\ttree.WalkDepthFirst(walkFn)\n}\n```\nOutput:\n```\n\u0026{Val:1 Left:\u003cnil\u003e Right:0xc00000c0a0}\n\u0026{Val:2 Left:0xc00000c0c0 Right:\u003cnil\u003e}\n\u0026{Val:3 Left:\u003cnil\u003e Right:\u003cnil\u003e}\n```\n\n### Walk Breadth-First\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sbourlon/go-lctree\"\n)\n\ntype TreeNode = lctree.TreeNode\n\nfunc mySolution() *TreeNode {\n\treturn lctree.Deserialize(\"[1,null,2,3]\")\n}\n\nfunc main() {\n\ttree := mySolution()\n\n\twalkFn := func(n *TreeNode, depth int) error {\n\t\tfmt.Printf(\"depth: %d\\t%+v\\n\", depth, n)\n\t\treturn nil\n\t}\n\n\ttree.WalkBreadthFirst(walkFn)\n}\n```\nOutput:\n```\ndepth: 0        \u0026{Val:1 Left:\u003cnil\u003e Right:0xc00000c0a0}\ndepth: 1        \u003cnil\u003e\ndepth: 1        \u0026{Val:2 Left:0xc00000c0c0 Right:\u003cnil\u003e}\ndepth: 2        \u0026{Val:3 Left:\u003cnil\u003e Right:\u003cnil\u003e}\ndepth: 2        \u003cnil\u003e\ndepth: 3        \u003cnil\u003e\ndepth: 3        \u003cnil\u003e\n```\n\n### Convert to DOT language for visualization\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sbourlon/go-lctree\"\n)\n\ntype TreeNode = lctree.TreeNode\n\nfunc mySolution() *TreeNode {\n\treturn lctree.Deserialize(\"[10,5,15,null,null,6,20]\")\n}\n\nfunc main() {\n\ttree := mySolution()\n\tfmt.Println(tree.DOT())\n}\n```\nOutput:\n```dot\ndigraph {\ngraph [ordering=\"out\"];\n10;\n5;\n15;\n6;\n20;\n10 -\u003e 5;\n10 -\u003e 15;\n15 -\u003e 6;\n15 -\u003e 20;\n}\n```\n\nthen convert into a png picture (e.g. tree.png):\n```\n$ dot -Tpng -o tree.png tree.dot\n```\nOutput:\n\n![tree.png](img/tree.png \"Tree PNG image from DOT\")\n\n## Contributing\nPull-requests, feature requests and issues are welcome.\n\n## License\n[ISC license](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbourlon%2Fgo-lctree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbourlon%2Fgo-lctree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbourlon%2Fgo-lctree/lists"}