✅Easy & Clean Understandable || All Languages Code With Complete Explaination✅🔥
Intuition\n* We can traverse the binary tree level by level, starting from the root. At each level, we first visit all the nodes from left to right and add thei
# Intuition\n* We can traverse the binary tree level by level, starting from the root. At each level, we first visit all the nodes from left to right and add their children to the queue. By the end of the traversal, the leftmost node in the bottom row will be the last\n node visited.\n\n# Approach\n  1. Initialize a queue for level order traversal.\n  2. Start from the root node and add it to the queue.\n  3. While the queue is not empty, remove the current node from the queue.\n  4. Add the right child of the current node to the queue if it exists.\n  5. Add the left child of the current node to the queue if it exists.\n  6. Repeat steps 3-5 until the queue is empty.\n  7. Return the value of the last node visited, which will be the leftmost node in\n     the bottom row.\n\n# Complexity\n- #### Time complexity: $$O(n)$$, where `n` is the number of nodes in the binary tree.We visit each node exactly once.\n\n- #### Space complexity: $$O(n)$$, in the worst case, the queue can hold all the nodes at the maximum depth of the tree.\n# CODE \n```Java []\nclass Solution {\n    public int findBottomLeftValue(TreeNode root) {\n\n        Queue<TreeNode> queue = new LinkedList<>();\n\n        TreeNode current = root;\n        queue.add(root);\n\n        while(!queue.isEmpty()){\n             current = queue.poll();\n            if(current.right!=null){\n                queue.add(current.right);\n            }\n            if(current.left!=null){\n                queue.add(current.left);\n            }\n        }\n        return current.val;\n        \n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    int findBottomLeftValue(TreeNode* root) {\n        std::queue<TreeNode*> queue;\n        TreeNode* current = root;\n        queue.push(root);\n\n        while (!queue.empty()) {\n            current = queue.front();\n            queue.pop();\n            if (current->right != nullptr) {\n                queue.push(current->right);\n            }\n            if (current->left != nullptr) {\n                queue.push(current->left);\n            }\n        }\n        return current->val;\n    }\n};\n\n```\n```Python []\nfrom collections import deque\n\nclass Solution:\n    def findBottomLeftValue(self, root: TreeNode) -> int:\n        queue = deque()\n        current = root\n        queue.append(root)\n\n        while queue:\n            current = queue.popleft()\n            if current.right:\n                queue.append(current.right)\n            if current.left:\n                queue.append(current.left)\n        \n        return current.val\n\n```\n```javascript []\nvar findBottomLeftValue = function(root) {\n    let queue = [];\n    let current = root;\n    queue.push(root);\n\n    while (queue.length > 0) {\n        current = queue.shift();\n        if (current.right !== null) {\n            queue.push(current.right);\n        }\n        if (current.left !== null) {\n            queue.push(current.left);\n        }\n    }\n    return current.val;\n};\n```\n```C []\n\nint findBottomLeftValue(struct TreeNode* root) {\n    struct TreeNode** queue = (struct TreeNode**)malloc(sizeof(struct TreeNode*) * 10000);\n    struct TreeNode* current = root;\n    int front = 0, rear = 0;\n    queue[rear++] = root;\n\n    while (front < rear) {\n        current = queue[front++];\n        if (current->right != NULL) {\n            queue[rear++] = current->right;\n        }\n        if (current->left != NULL) {\n            queue[rear++] = current->left;\n        }\n    }\n    int result = current->val;\n    free(queue);\n    return result;\n}\n```\n```C# []\nusing System.Collections.Generic;\n\npublic class Solution {\n    public int FindBottomLeftValue(TreeNode root) {\n        Queue<TreeNode> queue = new Queue<TreeNode>();\n        TreeNode current = root;\n        queue.Enqueue(root);\n\n        while (queue.Count > 0) {\n            current = queue.Dequeue();\n            if (current.right != null) {\n                queue.Enqueue(current.right);\n            }\n            if (current.left != null) {\n                queue.Enqueue(current.left);\n            }\n        }\n        return current.val;\n    }\n}\n\n```\n```PHP []\nclass Solution {\n    function findBottomLeftValue($root) {\n        $queue = new SplQueue();\n        $current = $root;\n        $queue->enqueue($root);\n\n        while (!$queue->isEmpty()) {\n            $current = $queue->dequeue();\n            if ($current->right !== null) {\n                $queue->enqueue($current->right);\n            }\n            if ($current->left !== null) {\n                $queue->enqueue($current->left);\n            }\n        }\n        return $current->val;\n    }\n}\n\n```\n```Typescript []\nclass Solution {\n    findBottomLeftValue(root: TreeNode | null): number {\n        let queue: TreeNode[] = [];\n        let current: TreeNode | null = root;\n        if (current !== null) {\n            queue.push(current);\n        }\n\n        while (queue.length > 0) {\n            current = queue.shift()!;\n            if (current.right !== null) {\n                queue.push(current.right);\n            }\n            if (current.left !== null) {\n                queue.push(current.left);\n            }\n        }\n        return current!.val;\n    }\n}\n\n```\n\n\n\n# Code With Complete Explaination\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nimport java.util.LinkedList;\nimport java.util.Queue;\n\nclass Solution {\n    // Method to find the value of the leftmost node in the bottom row of a binary tree\n    public int findBottomLeftValue(TreeNode root) {\n        // Create a queue to perform level order traversal\n        Queue<TreeNode> queue = new LinkedList<>();\n\n        // Start from the root node\n        TreeNode current = root;\n        // Add the root node to the queue\n        queue.add(root);\n\n        // Traverse the tree level by level\n        while (!queue.isEmpty()) {\n            // Remove the current node from the queue\n            current = queue.poll();\n            \n            // If the current node has a right child, add it to the queue\n            if (current.right != null) {\n                queue.add(current.right);\n            }\n            \n            // If the current node has a left child, add it to the queue\n            if (current.left != null) {\n                queue.add(current.left);\n            }\n        }\n        // Return the value of the leftmost node in the bottom row\n        return current.val;\n    }\n}\n\n```\n# Please UPVOTE If You Find Helpful\uD83E\uDD7A\uD83D\uDC4D\n\n
['Java']