SkillAgentSearch skills...

BinaryTree

LeetCode OJ's Binary Tree Visualization in Python

Install / Use

/learn @gavinhub/BinaryTree
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

BinaryTree for LeetCode

BinaryTree.py is a handy tool which can construct and display the binary trees you need when coding for LeetCode

DEMO

  1. You need to import the class before using it

     import BinaryTree as bt
    
  2. 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)
    
  3. Get the root of the binary tree

     r = t.root()
     print r 
     # Out: [4] Left -> None Right -> None
    
  4. Display the tree

     t.display()
    

    And you get:

            1               
           / \          
          /   \         
         /     \        
        /       \       
        2       3       
       / \       \    
      /   \       \   
      4   5       6   
     /             \ 
     7             8 
    
     
    
  5. 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

View on GitHub
GitHub Stars12
CategoryDevelopment
Updated1y ago
Forks3

Languages

Python

Security Score

60/100

Audited on May 19, 2024

No findings