摘要: 二叉树——113. 路径总和 II 题目: 思路: 前序遍历+回溯 代码参考:https://leetcode-cn.com/problems/path-sum-ii/solution/cqian-xu-bian-li-jia-hui-su-by-qing-feng-seve/ 代码: class 阅读全文
posted @ 2021-04-24 22:56 Originhhh 阅读(86) 评论(0) 推荐(0)
摘要: 二叉树——145. 二叉树的后序遍历 题目: 思路: 迭代,顺序是左右中 代码: class Solution { public: vector<int> postorderTraversal(TreeNode* root) { // 放结果 vector<int> res; postorder(r 阅读全文
posted @ 2021-04-24 21:27 Originhhh 阅读(48) 评论(0) 推荐(0)
摘要: 二叉树——129. 求根节点到叶节点数字之和 题目: 思路: DFS(深度搜索)+回溯 代码: class Solution { public: int sumNumbers(TreeNode* root) { if (!root) return 0; int res = 0; dfs(root, 阅读全文
posted @ 2021-04-24 20:58 Originhhh 阅读(116) 评论(0) 推荐(0)