Using LevelOrder Traversal (using a Queue)✅
Intuition\n Describe your first thoughts on how to solve this problem. To find the leftmost value in the last row of a binary tree, we can perform a level order
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->To find the leftmost value in the last row of a binary tree, we can perform a level order traversal. By traversing level by level and storing each level\'s values in a vector, we can easily access the last row and return its leftmost value.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Implement a level order traversal of the binary tree using a queue.\n- While traversing each level, store the values of the nodes in vectors representing each level.\n- After traversal, return the leftmost value of the last row, which corresponds to the first element of the last vector.\n\n# Complexity\n- Time complexity: `O(n)`, where $n$ is the number of nodes in the binary tree. We traverse each node exactly once.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity: `O(n)`, where $n$ is the number of nodes in the binary tree. The space complexity is dominated by the queue used for level order traversal and the vectors used to store the values of each level.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\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\nvector<vector<int>> levelOrder(TreeNode* root, vector<vector<int>> &ans) {\n        if(root==NULL)return ans;\n        queue<TreeNode*>q;\n        q.push(root);\n        while(!q.empty()){\n            int n=q.size();\n            vector<int>v;\n            for(int i=0; i<n; i++){\n                TreeNode* node=q.front();\n                q.pop();\n                v.push_back(node->val);\n                if(node->left) q.push(node->left);\n                if(node->right) q.push(node->right);\n            }\n            ans.push_back(v);\n        }\n        return ans;\n    }\n    int findBottomLeftValue(TreeNode* root) {\n        vector<vector<int>> ans;\n        ans = levelOrder(root, ans);\n        int n = ans.size();\n        int m = ans[n-1].size();\n        return ans[n-1][0];\n    }\n};\n```
['Tree', 'Queue', 'C++']