摘要: 二叉树的层序遍历(bfs) ✅做题思路or感想: 利用队列来实现层序遍历 当明确每一层直接的元素不用区别对待时,其实代码中的size可以不写,但在这里要根据每一层来进行分组,所以要写size 当队列为空时,结束bfs class Solution { public: vector<vector<in 阅读全文
posted @ 2022-03-26 14:03 北原春希 阅读(23) 评论(0) 推荐(0)
摘要: 二叉树的遍历 前序遍历 遍历顺序:中,左,右 代码实现: void dfs(TreeNode* root) { if (root != nullptr)result.push_back(root->val); if (root->left != nullptr)dfs(root->left); if 阅读全文
posted @ 2022-03-26 13:48 北原春希 阅读(40) 评论(0) 推荐(0)