diff --git a/problems/0513.找树左下角的值.md b/problems/0513.找树左下角的值.md index e3be8905..ac21dc68 100644 --- a/problems/0513.找树左下角的值.md +++ b/problems/0513.找树左下角的值.md @@ -217,7 +217,9 @@ public: Java: + ```java +// 递归法 class Solution { private int Deep = -1; private int value = 0; @@ -241,6 +243,36 @@ class Solution { } ``` +```java +//迭代法 +class Solution { + + public int findBottomLeftValue(TreeNode root) { + Queue 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: