随笔分类 - 二叉树
摘要:前序遍历 前序与后序代码几乎完全相同,唯一区别是入栈的顺序,前序入栈右左根,出栈为根左右, 后序入栈左右根,出栈为根右左,然后再反转一下就是后序遍历的左右根 class Solution { public: vector<int> res; vector<int> preorderTraversal
阅读全文
摘要:老忘咋写,贴这记录下 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nu
阅读全文
摘要:学习资料 1.推断二叉树 2.AcWing 3598. 二叉树遍历(暑假每日一题2022) 1.函数对比 前序中序推后序 void dfs(string mid, string pre) { if (mid.size()) { char root = pre[0]; int cur = mid.fi
阅读全文
摘要:传递悄悄话 层序遍历数组形式的下标如下 #include <algorithm> #include <cstring> #include <iostream> using namespace std; const int N = 1010, M = N * 2; int n; int h[N], e
阅读全文