Easy iterative solution with Explanation || cpp || py || java || js
Intuition\nThe intuition is focused on utilizing the level-order traversal to systematically process the tree, considering the leftmost element in each level, a
# Intuition\nThe intuition is focused on utilizing the level-order traversal to systematically process the tree, considering the leftmost element in each level, and ultimately identifying the bottom-left node.\n\n# Approach\n\nInitialize Queue and Check for Empty Tree:\nStart by initializing a queue for the level-order traversal.\nIf the tree is empty (root is NULL), return 0 as there is no bottom-left node.\n\nBFS Traversal (Level-Order):\nUse a while loop to traverse the tree level by level.\nIn each iteration, process nodes at the current level.\nUpdate leftnode with the value of the leftmost node at the current level(which will present in front() of the queue in each level).\n\nIterate Until the Last Level:\nContinue the traversal until the queue is empty.\nAt the end of the traversal, leftnode will store the value of the bottom-left node.\nReturn Result:\n\nReturn the value stored in leftnode as the final result.\n\n\n# Complexity\n- Time complexity:\nThe time complexity is O(n), where n is the number of nodes in the binary tree. This is because each node is visited once in the level-order traversal.\n\n- Space complexity:\nThe space complexity is O(w), where w is the maximum width (number of nodes at the widest level) of the binary tree. In the worst case, the queue can contain all nodes at the last level, which is the maximum width of the tree.\n\n```c++ []\nclass Solution {\npublic:\n    int findBottomLeftValue(TreeNode* root) \n    {\n        queue<TreeNode*> q;\n        if(root==NULL)return 0;\n        q.push(root);\n        int leftnode ;\n        while(!q.empty())\n        {\n            int size = q.size();\n            leftnode = q.front()->val;\n            while(size--)\n            {\n                auto tmp= q.front();\n                q.pop();\n                if(tmp->left)\n                    q.push(tmp->left);\n                if(tmp->right)\n                    q.push(tmp->right);\n            }\n        }\n        return leftnode;\n    }\n};\n```\n```java []\npublic class Solution {\n    public int findBottomLeftValue(TreeNode root) {\n        if (root == null)\n            return 0;\n\n        Queue<TreeNode> q = new LinkedList<>();\n        q.add(root);\n        int leftNode = 0;\n\n        while (!q.isEmpty()) {\n            int size = q.size();\n            leftNode = q.peek().val;\n\n            for (int i = 0; i < size; i++) {\n                TreeNode tmp = q.poll();\n                if (tmp.left != null)\n                    q.add(tmp.left);\n                if (tmp.right != null)\n                    q.add(tmp.right);\n            }\n        }\n\n        return leftNode;\n    }\n}\n```\n```python []\nclass Solution:\n    def findBottomLeftValue(self, root):\n        if not root:\n            return 0\n        \n        q = Queue()\n        q.put(root)\n        left_node = 0\n\n        while not q.empty():\n            size = q.qsize()\n            left_node = q.queue[0].val\n            \n            for i in range(size):\n                tmp = q.get()\n                if tmp.left:\n                    q.put(tmp.left)\n                if tmp.right:\n                    q.put(tmp.right)\n\n        return left_node\n```\n\n```javascript []\n/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n *     this.val = (val===undefined ? 0 : val)\n *     this.left = (left===undefined ? null : left)\n *     this.right = (right===undefined ? null : right)\n * }\n */\n\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar findBottomLeftValue = function(root) {\n    if (!root) {\n        return 0;\n    }\n\n    let queue = [root];\n    let leftNode = 0;\n\n    while (queue.length > 0) {\n        let size = queue.length;\n        leftNode = queue[0].val;\n\n        for (let i = 0; i < size; i++) {\n            let tmp = queue.shift();\n            if (tmp.left) {\n                queue.push(tmp.left);\n            }\n            if (tmp.right) {\n                queue.push(tmp.right);\n            }\n        }\n    }\n\n    return leftNode;\n};\n```\n![upvote.jpeg](https://assets.leetcode.com/users/images/ce9d71f8-ede3-4bf4-9aa5-3751bec26bd6_1709092102.428923.jpeg)\n
['Breadth-First Search', 'Queue', 'Binary Tree', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']