uacs2024

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

10 2022 档案

leetcode429-N 叉树的层序遍历
摘要:429. N 叉树的层序遍历 BFS非递归,自己写的。 /* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; 阅读全文

posted @ 2022-10-31 16:40 ᶜʸᵃⁿ 阅读(12) 评论(0) 推荐(0) 编辑

leetcode199-二叉树的右视图
摘要:199. 二叉树的右视图 这道题BFS很容易想到。但DFS没想出来。 这是BFS vector<int> rightSideView(TreeNode* root) { if(root==nullptr) return {}; queue<TreeNode*> qqq; vector<int> re 阅读全文

posted @ 2022-10-31 15:38 ᶜʸᵃⁿ 阅读(12) 评论(0) 推荐(0) 编辑

leetcode103-二叉树的锯齿形层序遍历
摘要:103. 二叉树的锯齿形层序遍历 用两个栈来实现。先把根节点放入第一个栈。循环内部根据哪个栈为空判断新的节点放到哪个栈,确定先左还是先右。当两个栈都为空时,循环结束。 /** * Definition for a binary tree node. * struct TreeNode { * int 阅读全文

posted @ 2022-10-30 13:54 ᶜʸᵃⁿ 阅读(21) 评论(0) 推荐(0) 编辑

leetcode102-二叉树的层序遍历
摘要:102. 二叉树的层序遍历 有两种实现方法。第一种是递归,第二种是队列实现。第一种是看了别人的代码写出来的,第二种是自己写的。这道题的不能直接把遍历得到的数字直接塞进res里,需要区分不同的层次。所以返回的是二维vector 递归 index用来表示这是第几层,要放到哪一个一维数组 class So 阅读全文

posted @ 2022-10-30 10:51 ᶜʸᵃⁿ 阅读(23) 评论(0) 推荐(0) 编辑

卡尔的二叉树前序中序后序遍历的统一写法,理解起来还是有点难的
摘要:这是链接 阅读全文

posted @ 2022-10-29 16:03 ᶜʸᵃⁿ 阅读(12) 评论(0) 推荐(0) 编辑

leetcode94-二叉树的中序遍历
摘要:94. 二叉树的中序遍历 迭代法,看别人的代码的,还需要琢磨一下 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNo 阅读全文

posted @ 2022-10-29 15:49 ᶜʸᵃⁿ 阅读(16) 评论(0) 推荐(0) 编辑

leetcode145-二叉树的后序遍历 ps:后序遍历的迭代法感觉远远比前序中序的迭代法要难
摘要:145. 二叉树的后序遍历 class Solution { public: vector<int> res; void Tracking(TreeNode* root) { if(root==nullptr) return; Tracking(root->left); Tracking(root- 阅读全文

posted @ 2022-10-28 19:42 ᶜʸᵃⁿ 阅读(17) 评论(0) 推荐(0) 编辑

leetcode1002-查找共用字符
摘要:1002. 查找共用字符 class Solution { public: vector<string> commonChars(vector<string>& words) { int size=words.size(); vector<string> res; int alp[26]={0}; 阅读全文

posted @ 2022-10-23 16:14 ᶜʸᵃⁿ 阅读(16) 评论(0) 推荐(0) 编辑

leetcode84-柱状图中最大的矩形
摘要:84. 柱状图中最大的矩形 两个星期没写leetcode就连暴力解法都写不出了。 暴力解法 class Solution { public: int largestRectangleArea(vector<int>& heights) { int size=heights.size(),maxSiz 阅读全文

posted @ 2022-10-08 16:14 ᶜʸᵃⁿ 阅读(15) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示