# Find-Bottom-Left-Tree

Dec 07, 2017

Given a binary tree, find the leftmost value in the last row of the tree.

Example 1: Input:

2


/
1 3

Output: 1 Example 2: Input:

    1
/ \
2   3
/   / \
4   5   6
/
7


Output: 7 Note: You may assume the tree (i.e., the given root node) is not NULL.

int findBottomLeftValue(TreeNode *root,int &height) {
if (root == nullptr) {
height = -1;
return -1;
}
if (root->left == nullptr && root->right == nullptr)
return root->val;
int lefth,righth;
lefth = righth = height + 1;
int left = findBottomLeftValue(root->left,lefth);
int right = findBottomLeftValue(root->right,righth);
if (lefth >= righth) {
height = lefth;
return left;
} else{
height = righth;
return right;
}
}
int findBottomLeftValue(TreeNode* root) {
int h = 0;
return findBottomLeftValue(root,h);
}


public int findLeftMostNode(TreeNode root) {
while (!queue.isEmpty()) {
root = queue.poll();
if (root.right != null)
if (root.left != null)
}
return root.val;
}


def findLeftMostNode(self, root):
queue = [root]
for node in queue:
queue += filter(None, (node.right, node.left))
return node.val

LeetCodeLeetCode

Find-Peak-Element

Count-Numbers-with-Unique-Digits