mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-02 18:39:09 +08:00
Merge branch 'master' into patch-14
This commit is contained in:
@@ -217,8 +217,36 @@ public:
|
||||
|
||||
|
||||
Java:
|
||||
|
||||
```java
|
||||
// 递归法
|
||||
class Solution {
|
||||
private int Deep = -1;
|
||||
private int value = 0;
|
||||
public int findBottomLeftValue(TreeNode root) {
|
||||
value = root.val;
|
||||
findLeftValue(root,0);
|
||||
return value;
|
||||
}
|
||||
|
||||
private void findLeftValue (TreeNode root,int deep) {
|
||||
if (root == null) return;
|
||||
if (root.left == null && root.right == null) {
|
||||
if (deep > Deep) {
|
||||
value = root.val;
|
||||
Deep = deep;
|
||||
}
|
||||
}
|
||||
if (root.left != null) findLeftValue(root.left,deep + 1);
|
||||
if (root.right != null) findLeftValue(root.right,deep + 1);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
//迭代法
|
||||
class Solution {
|
||||
|
||||
public int findBottomLeftValue(TreeNode root) {
|
||||
Queue<TreeNode> queue = new LinkedList<>();
|
||||
queue.offer(root);
|
||||
@@ -243,6 +271,8 @@ class Solution {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
Python:
|
||||
|
||||
|
||||
@@ -255,4 +285,4 @@ Go:
|
||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
||||
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
|
||||
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>
|
||||
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>
|
||||
Reference in New Issue
Block a user