代码随想录打卡第16天 | 513. 找树左下角的值、112. 路径总和、113. 路径总和II、106. 从中序与后序遍历序列构造二叉树、105. 从前序与中序遍历序列构造二叉树
513. 找树左下角的值 链接:513. 找树左下角的值 文章:代码随想录 视频:B站讲解 状态:✅ 第一想法 层序遍历,每层的第一个值 看完题解后的想法 实现中遇到的困难 代码 class Solution { public: int findBottomLeftValue(TreeNode* root) { int res; if (!root) { return res; } queue<TreeNode*> q; q.push(root); while (!q.empty()) { int num = q.size(); for (int i = 0; i < num; i++) { TreeNode* cur = q.front(); q.pop(); if (i == 0) { res = cur->val; } if (cur->left) { q.push(cur->left); } if (cur->right) { q.push(cur->right); } } } return res; } }; 112. 路径总和 链接:112. 路径总和 文章:代码随想录 视频:B站讲解 状态:✅ 第一想法 DFS+回溯;栈自带回溯; ...