Easy solution  in c++/Python/Java/Javascript with explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst thought that comes in mind is using dfs and traverse to left most node but it wil
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst thought that comes in mind is using dfs and traverse to left most node but it will end up in giving wrong answer as the height is the main factor so to came up with a better solution bfs would be a good approach to traverse level wise \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTo understand the approach for the provided code snippet, let\'s break it down step by step:\n\n Objective: The goal of this code is to find the value of the leftmost node in the bottom level of a binary tree.\n    Algorithm:\n \n The code uses a breadth-first search (BFS) approach to traverse the binary tree level by level.\n \nIt starts by initializing a queue q with the root node.\nThen, it enters a loop where it dequeues a node, checks if it has a right child, and if so, adds it to the queue. Next, it checks for a left child and adds it to the queue.\n\nBy doing this level-order traversal, the last node visited will be the leftmost node at the bottom level of the tree.\n    Key Points:\nThe code prioritizes visiting right child nodes before left child nodes in each level.\n\nThe final value returned is from the last node visited, which will be the leftmost node at the deepest level of the tree.\n\nThis approach ensures that by traversing the tree level by level from left to right, we can find and return the value of the leftmost node at the deepest level of the binary tree.\n\n\n# Complexity\n- Time complexity:0(n) each node is traversed once\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:0(n) because of queue\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```c++ []\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    int findBottomLeftValue(TreeNode* root) {\n        queue<TreeNode*>q;\n\n        q.push(root);\n        TreeNode *a=NULL;\n        while(!q.empty()){\n            a = q.front();\n            q.pop();\n\n            if(a->right){\n                q.push(a->right);\n            }\n            if(a->left){\n                q.push(a->left);\n            }\n        }\n        return a->val;\n    }\n};\n```\n```java []\nimport java.util.LinkedList;\nimport java.util.Queue;\n\nclass TreeNode {\n    int val;\n    TreeNode left;\n    TreeNode right;\n\n    TreeNode() {}\n\n    TreeNode(int x) {\n        val = x;\n    }\n\n    TreeNode(int x, TreeNode left, TreeNode right) {\n        val = x;\n        this.left = left;\n        this.right = right;\n    }\n}\n\nclass Solution {\n    public int findBottomLeftValue(TreeNode root) {\n        Queue<TreeNode> q = new LinkedList<>();\n        q.offer(root);\n        TreeNode leftmost = null;\n\n        while (!q.isEmpty()) {\n            leftmost = q.poll();\n\n            if (leftmost.right != null) {\n                q.offer(leftmost.right);\n            }\n            if (leftmost.left != null) {\n                q.offer(leftmost.left);\n            }\n        }\n\n        return leftmost.val;\n    }\n}\n\n```\n``` Javascript []\nclass TreeNode {\n    constructor(val = 0, left = null, right = null) {\n        this.val = val;\n        this.left = left;\n        this.right = right;\n    }\n}\n\nvar findBottomLeftValue = function(root) {\n    const queue = [root];\n    let leftmost = null;\n\n    while (queue.length > 0) {\n        leftmost = queue.shift();\n\n        if (leftmost.right) {\n            queue.push(leftmost.right);\n        }\n        if (leftmost.left) {\n            queue.push(leftmost.left);\n        }\n    }\n\n    return leftmost.val;\n};\n\n```\n``` Python3 []\nclass Solution:\n    def findBottomLeftValue(self, root: Optional[TreeNode]) -> int:\n        if not root:\n            return None\n        \n        queue = deque([root])\n        leftmost = None\n\n        while queue:\n            leftmost = queue.popleft()\n\n            if leftmost.right:\n                queue.append(leftmost.right)\n            if leftmost.left:\n                queue.append(leftmost.left)\n\n        return leftmost.val\n```
['Tree', 'Breadth-First Search', 'Binary Tree', 'C++', 'Java', 'Python3', 'JavaScript']