| C++ || Well Explained |
\nIf we have one node in tree, return it as it is the left most value in last row itself.\nMake a queue to store treenodes and push root to it, initialize final
```\nIf we have one node in tree, return it as it is the left most value in last row itself.\nMake a queue to store treenodes and push root to it, initialize final result to 0.\nTill the queue is empty do the following : ( BTW queue empty means tree traversal is complete )\nTake queue size into n annd traverse each level based on queue size.\nNow lets see whats happening when we are traversing nth level :\nWe are extracting node from queue and popping it from queue cause we are done with it.\nNow heart of this question: if(i==0) means we are on left most node of any level , in such case update res with that node value. \nNow keep on adding left and right nodes if exists for temp into your queue and repeat same procedure\nfor all nodes of a level. When we comes out of for loop , We will check if queue is empty if not what is its size that will be in n.\nNow go for next level order traversal in similar fashion.\nLets take an example : \n     1\n  2     3\n4     5   6\n   7\nwe have this tree in this case, while loop will execute 4 times as there are 4 levels.\nInner for loop will execute depending upon number of nodes on each level. like 1 time for 1st level, \n2 times for 2nd level, 3 times for 3rd level, 1 time for 4th level. Heart of our question : if(i==0) will execute h times , h = no. of levels = 4 times.\nWhy ? because on each level we have a left most node like 1 , 2 , 4 and 7 . see the tree\nBasically res is being updated till the last level. Now tree is traversed as queue is empty so return res which is 7 that should be our output.\nyes, complexity :\nAt most we are using a queue to store nodes of tree and its maximum size can grow to max number of nodes that can be \nthere at a particular level. so Space comp : O(k) where k is max number of nodes at any level.\nTime comp : O(n) where n is number of nodes in tree as we are visiting each node in tree once.\nupvote if you like it.\n```\n\n```\nclass Solution {\npublic:\n    \n    int findBottomLeftValue(TreeNode* root) \n    {\n        if(root->left == NULL && root->right == NULL)\n            return root->val;\n        \n        queue <TreeNode*> q;\n        q.push(root);\n        int res = 0;\n        \n        while(!q.empty())\n        {\n            int size = q.size();\n            for(int i=0; i<size; i++)\n            {\n                TreeNode* temp = q.front();\n                q.pop();\n                if(i == 0)\n                   res = temp->val;\n                if(temp->left)\n                    q.push(temp->left);\n                if(temp->right)\n                    q.push(temp->right);\n            }\n        }\n        return res;\n    }\n};\n```
['Breadth-First Search', 'Queue', 'C', 'C++']