BinaryTree
LeetCode OJ's Binary Tree Visualization in Python
Install / Use
/learn @gavinhub/BinaryTreeREADME
BinaryTree for LeetCode
BinaryTree.py is a handy tool which can construct and display the binary trees you need when coding for LeetCode
DEMO
-
You need to import the class before using it
import BinaryTree as bt -
Construct a binary tree from a list of values/objects or a binary tree
t1 = bt.BinaryTree([1,2,3,4,5,'#',6,7,'#','#','#','#',8]) t2 = bt.BinaryTree(t1.root()) node = bt.TreeNode(4) -
Get the root of the binary tree
r = t.root() print r # Out: [4] Left -> None Right -> None -
Display the tree
t.display()And you get:
1 / \ / \ / \ / \ 2 3 / \ \ / \ \ 4 5 6 / \ 7 8 -
Test
python -m unittest -v test
LeetCode Binary Tree Serialization
See LeetCode, click "read more on how binary tree is serialized on OJ"
Related Skills
node-connect
337.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
337.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.2kCommit, push, and open a PR
