mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
@ -217,7 +217,9 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
Java:
|
Java:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
// 递归法
|
||||||
class Solution {
|
class Solution {
|
||||||
private int Deep = -1;
|
private int Deep = -1;
|
||||||
private int value = 0;
|
private int value = 0;
|
||||||
@ -241,6 +243,36 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
//迭代法
|
||||||
|
class Solution {
|
||||||
|
|
||||||
|
public int findBottomLeftValue(TreeNode root) {
|
||||||
|
Queue<TreeNode> queue = new LinkedList<>();
|
||||||
|
queue.offer(root);
|
||||||
|
int res = 0;
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
int size = queue.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
TreeNode poll = queue.poll();
|
||||||
|
if (i == 0) {
|
||||||
|
res = poll.val;
|
||||||
|
}
|
||||||
|
if (poll.left != null) {
|
||||||
|
queue.offer(poll.left);
|
||||||
|
}
|
||||||
|
if (poll.right != null) {
|
||||||
|
queue.offer(poll.right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user