1、题目描述
2、问题分析
使用层序遍历思想
3、代码
1 int findBottomLeftValue(TreeNode* root) { 2 if (root == NULL) 3 return 0; 4 queue<TreeNode*> q; 5 q.push(root); 6 7 int val = 0; 8 while (!q.empty()) { 9 int size = q.size(); 10 for(int i = 0; i < size; i++) { 11 TreeNode *node = q.front(); 12 if (node->left != NULL) 13 q.push(node->left); 14 if (node->right != NULL) 15 q.push(node->right); 16 17 18 if (i == 0) 19 val = node->val; 20 q.pop(); 21 } 22 } 23 return val; 24 }