BFS | Level order traversal
Intuition\nLevel order traversal\n# Approach\nPerforms a level order traversal of the binary tree and keeps updating the leftmost value found so far until reach
# Intuition\nLevel order traversal\n# Approach\nPerforms a level order traversal of the binary tree and keeps updating the leftmost value found so far until reaching the last level, then returns the value of the leftmost node in the last level.\n\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    int findBottomLeftValue(TreeNode* root) {\n        queue<TreeNode*>q;\n        q.push(root);\n        int ans = root->val;\n        while(!q.empty()){\n            int size = q.size();\n            ans = q.front()->val;\n            while(size--){\n                TreeNode* front = q.front();\n                q.pop();\n\n                if(front->left != NULL)q.push(front->left);\n                if(front->right != NULL)q.push(front->right);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']