摘要: 题目 1 class Solution { 2 public: 3 vector<int>ans; 4 vector<int> postorder(Node* root) { 5 dfs(root); 6 return ans; 7 } 8 void dfs(Node* root){ 9 if(ro 阅读全文
posted @ 2021-01-10 18:12 Uitachi 阅读(81) 评论(0) 推荐(0)
摘要: 题目 法一、递归 1 class Solution { 2 public: 3 vector<int>ans; 4 void dfs(Node* root){ 5 if(root!=NULL){ 6 ans.push_back(root->val); 7 for(int i = 0;i < root 阅读全文
posted @ 2021-01-10 17:56 Uitachi 阅读(79) 评论(0) 推荐(0)
摘要: 题目 本题目一开始想要通过二叉树遍历KMP匹配,但看来实现比较复杂 不如直接暴力匹配,本题和LeetCode100.相同的树有共通之处 1 class Solution { 2 public: 3 bool isSubtree(TreeNode* s, TreeNode* t) { 4 if(!s 阅读全文
posted @ 2021-01-10 17:24 Uitachi 阅读(73) 评论(0) 推荐(0)
摘要: 题目 1 class Solution { 2 public: 3 int ans = 0; 4 int findTilt(TreeNode* root) { 5 postOrder(root); 6 return ans; 7 } 8 int postOrder(TreeNode* root){ 阅读全文
posted @ 2021-01-10 16:37 Uitachi 阅读(59) 评论(0) 推荐(0)
摘要: 题目 法一、层序遍历 1 class Solution { 2 public: 3 int maxDepth(Node* root) { 4 if(root== NULL) return 0; 5 queue<Node*>q;int level = 0;int lc = 0; 6 q.push(ro 阅读全文
posted @ 2021-01-10 15:46 Uitachi 阅读(75) 评论(0) 推荐(0)
摘要: 题目 1 class Solution { 2 public: 3 int minimum = INT_MIN; 4 vector<int>res; 5 int diameterOfBinaryTree(TreeNode* root) { 6 if(root == NULL) return 0; 7 阅读全文
posted @ 2021-01-10 15:13 Uitachi 阅读(82) 评论(0) 推荐(0)