minimum generation tree -template scar

2023-03-14   ES  

 Leetcode 94. Mid -sequential traversal 
 Given a binary tree, return to its medium -order traversal 
 '' ' 
 # Definition for a binary tree node. 
 class time: 
     def __init __ (self, x): 
         Self.val = x 
         Self.left = None 
         Self.richt = None 

 class solution: 
     DEF InrentRTRAVERSAL (Self, ROOT: Treenode): 
         if root is none: 
             Return [] 
         if root.left is none and root.richt is none: 
             Return [root.val] 
         stack = []# Constructing auxiliary stack 
         curr = root 
         While (Curr): 
             stack.append (curr) 
             Curr = Curr.Left 
         result = [] 
         While (stack): 
             Curr = Stack.pop (-1) 
             # The current node out of the stack, indicating that all elements in the left sub -tree of the current node have been accessed 
             Result.append (Curr.val) 
             if curr.right is not none: 
                 Curr = Curr.right 
                 While (Curr): 
                     stack.append (curr) 
                     Curr = Curr.Left 
         Return Result 

 if __Name __ == "__ Main__": 
     root = timeode (1) 
     root.richt = Treenode (3) 
     root.left = timeode (2) 
     root.left.left = Treenode (4) 
     root.left.richt = Treenode (5) 
     root.richt.richt = Treenode (7) 
     Print (solution (). Inordertraversal (root)) 
     # [4,2,5,1,3,7]


Related Posts

Caddy & GRPC (3) Add a reverse proxy plug -in to Caddy

Python 3.8 version, install and use the Pymouse library

java thread pool?

[Establishing Oracle 19C on Oracle Linux 7 -Single instance database based on ASM storage]

minimum generation tree -template scar

Random Posts

database engineering -mybatis (1)

MySQL InsertorUpDate is updated, and inserts in CAPPADOCIA when there is no existence

WMI009-WMI Learning Notes (9) -System.Management and System.Management.Instrumentation namespaces (name space)

qt configuration system new project function

Connect the server through the IP address and port