Level Order Traversal || C++ || Beats 86%
Intuition\nJust add the first element of every level in a vector and at the end return the last element of that vector.\n Describe your first thoughts on how to
# Intuition\nJust add the first element of every level in a vector and at the end return the last element of that vector.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nMaintain a Queue of Node and Level of that node, if level == vector\'s size then add that node because it is the first node of that level.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\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    int findBottomLeftValue(TreeNode* root) {\n\n        ios_base::sync_with_stdio(false);\n        cin.tie(NULL);\n        cout.tie(NULL);\n\n        if(!root) return 0;\n        \n        //Node,Level\n        queue<pair<TreeNode*,int>> q;\n        vector<int> ans;\n\n        q.push({root,0});\n\n        while(!q.empty()){\n            TreeNode* node = q.front().first;\n            int level = q.front().second;\n\n            q.pop();\n\n            if(ans.size() == level){\n                ans.push_back(node->val);\n            }\n\n            if(node->left){\n                q.push({node->left,level+1});\n            }\n            if(node->right){\n                q.push({node->right,level+1});\n            }\n        }\n\n        return ans[ans.size()-1];\n    }\n};\n```
['Tree', 'Binary Tree', 'C++']