@@ -12,6 +12,7 @@ No.|Title|Difficulty|Solved|Date
12
12
222|[ Count Complete Tree Nodes] ( https://leetcode.com/problems/count-complete-tree-nodes/ ) |Medium|yes|2019-01-04
13
13
257|[ Binary Tree Paths] ( https://leetcode.com/problems/binary-tree-paths/ ) |Easy|yes|2019-01-12
14
14
297|[ Serialize and Deserialize Binary Tree] ( https://leetcode.com/problems/serialize-and-deserialize-binary-tree/ ) |Hard|yes|2019-01-05
15
+ 513|[ Find Bottom Left Tree Value] ( https://leetcode.com/problems/find-bottom-left-tree-value/ ) |Medium|yes|2019-01-14
15
16
543|[ Diameter of Binary Tree] ( https://leetcode.com/problems/diameter-of-binary-tree/ ) |Easy|yes|2019-01-05
16
17
589|[ N-ary Tree Preorder Traversal] ( https://leetcode.com/problems/n-ary-tree-preorder-traversal/ ) |Easy|yes|2019-01-05
17
18
590|[ N-ary Tree Postorder Traversal] ( https://leetcode.com/problems/n-ary-tree-postorder-traversal/ ) |Easy|yes|2019-01-05
@@ -80,6 +81,30 @@ No.|Title|Difficulty|Solved|Date
80
81
81
82
使用中序遍历来序列化二叉树。在进行反序列化二叉树的时候,使用递归的方式来进行。处理的第一个节点总是中间节点.
82
83
84
+ 513 . [ Find Bottom Left Tree Value] ( https://leetcode.com/problems/find-bottom-left-tree-value/ )
85
+
86
+ 简单的,当然可以通过层次遍历来解决。
87
+
88
+ 相对而言,更优美的方案是,递归的进行二叉树高度的比较。如果左右子树高度相当,则取左子树继续处理。最后处理到的节点,即是结果节点。
89
+
90
+ ``` java
91
+ public int findBottomLeftValue(TreeNode root) {
92
+ if (root. left == null && root. right == null ) return root. val;
93
+ int l = maxDepth(root. left);
94
+ int r = maxDepth(root. right);
95
+ if (l >= r) {
96
+ return findBottomLeftValue(root. left);
97
+ } else {
98
+ return findBottomLeftValue(root. right);
99
+ }
100
+ }
101
+
102
+ private int maxDepth(TreeNode node) {
103
+ if (node == null ) return 0 ;
104
+ return 1 + Math . max(maxDepth(node. left), maxDepth(node. right));
105
+ }
106
+ ```
107
+
83
108
543 . [ Diameter of Binary Tree] ( https://leetcode.com/problems/diameter-of-binary-tree/ )
84
109
85
110
对于特定的某个节点,最大的长度为左子树的高度+右子树的高度。然后进行递归的求解。
0 commit comments