In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Java binary tree and N-tree example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
Topic one
Solution method
/ * Definition for a binary tree node. * public class TreeNode {* int val; * TreeNode left; * TreeNode right; * TreeNode () {} * TreeNode (int val) {this.val = val;} * TreeNode (int val, TreeNode left, TreeNode right) {* this.val = val; * this.left = left; * this.right = right * / class Solution {StringBuffer sb = new StringBuffer (); List list = new ArrayList (); public List binaryTreePaths (TreeNode root) {method (root); return list;} public void method (TreeNode root) {if (root==null) return; int t = sb.length (); sb.append (root.val) If (root.left==null&&root.right==null) {list.add (sb.toString ());} sb.append ("- >"); method (root.left); method (root.right); sb.delete (t, sb.length ());}} topic 2
Solution method
/ * Definition for a binary tree node. * public class TreeNode {* int val; * TreeNode left; * TreeNode right; * TreeNode () {} * TreeNode (int val) {this.val = val;} * TreeNode (int val, TreeNode left, TreeNode right) {* this.val = val; * this.left = left; * this.right = right; *} * * / class Solution {int ans = 0 Public int sumOfLeftLeaves (TreeNode root) {method (root,false); return ans;} public void method (TreeNode root,boolean flag) {if (root==null) return; if (root.left==null&&root.right==null&&flag) {ans+=root.val; return;} method (root.left,true); method (root.right,false);} topic 3
Solution method
/ * / Definition for a Node.class Node {public int val; public List children; public Node () {} public Node (int _ val) {val = _ val;} public Node (int _ val, List _ children) {val = _ val; children = _ children;}}; * / class Solution {public int maxDepth (Node root) {if (root==null) {return 0 } int maxChildDepth = 0; for (int I = 0 position I)
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.