:type root: TreeNode :rtype: int
(self, root)
| 70 | |
| 71 | class Solution(object): |
| 72 | def findBottomLeftValue(self, root): |
| 73 | """ |
| 74 | :type root: TreeNode |
| 75 | :rtype: int |
| 76 | """ |
| 77 | waiting_for_access = [root] |
| 78 | new_waiting_for_access = [] |
| 79 | result = root.val |
| 80 | |
| 81 | while 1: |
| 82 | while waiting_for_access: |
| 83 | node = waiting_for_access.pop() |
| 84 | |
| 85 | if node.right: |
| 86 | new_waiting_for_access.append(node.right) |
| 87 | result = node.right.val |
| 88 | if node.left: |
| 89 | new_waiting_for_access.append(node.left) |
| 90 | result = node.left.val |
| 91 | if not new_waiting_for_access: |
| 92 | return result |
| 93 | waiting_for_access.extend(new_waiting_for_access[::-1]) |
| 94 | new_waiting_for_access = [] |