In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to return to the subsequent traversal of the python binary tree, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
1. Brief introduction of the problem.
Given a binary tree, return its post-order traversal.
2, example
Input: [1memnullre2] 1 / 2 / 3 output: [3meme2pence 1]
3, the train of thought of solving the problem
Solve the problem by recursion
4, problem solving procedure
Import java.util.ArrayList;import java.util.List
Public class PostorderTraversalTest2 {public static void main (String [] args) {TreeNode T1 = new TreeNode (1); TreeNode T2 = new TreeNode (2); TreeNode T3 = new TreeNode (3); t1.right = T2; t2.left = T3; List list = postorderTraversal (T1); System.out.println ("list =" + list)
}
Private static List list = new ArrayList ()
Public static List postorderTraversal (TreeNode root) {if (root = = null) {return list;} dfs (root); return list;}
Private static void dfs (TreeNode root) {if (root.left! = null) {dfs (root.left);} if (root.right! = null) {dfs (root.right);} list.add (root.val);}}
5. Picture version of the problem solving program.
The above is how to return the post-order traversal of the python binary tree. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.