摘要: 1.删除排序数组中的重复项 思路解析:本题的主要目的是删除重复项,限制是:1.数组是排序数组;2.必须原地修改;那其实只需要遍历然后把不同项前移 代码: class Solution { public int removeDuplicates(int[] nums) { int i = 0, j = 阅读全文
posted @ 2021-03-05 13:48 是水泵呢 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 贪心算法 class Solution { public: vector<vector<int>> restoreMatrix(vector<int>& rowSum, vector<int>& colSum) { int row = rowSum.size(); int col = colSum. 阅读全文
posted @ 2020-10-04 00:54 是水泵呢 阅读(148) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: vector<string> alertNames(vector<string>& keyName, vector<string>& keyTime) { map<string, set<string> > mp; int n = keyName.s 阅读全文
posted @ 2020-10-04 00:36 是水泵呢 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 层序遍历 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NUL 阅读全文
posted @ 2020-09-12 17:08 是水泵呢 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 题目大意:给出n和n个数的序列a和b,a为原始序列,b为排序其中的一个步骤,问b是a经过了堆排序还是插入排序的,并且输出它的下一步~ 分析:插入排序的特点是:b数组前面的顺序是从小到大的,后面的顺序不一定,但是一定和原序列的后面的顺序相同~所以只要遍历一下前面几位,遇到不是从小到大的时候,开始看b和 阅读全文
posted @ 2020-09-12 16:39 是水泵呢 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 思路 因为是二叉搜索树,所以树的中序遍历是从小到大排序的一组数 所以将位子中序遍历保存后,将已经排序过后的数一一对应即可找到位置 最后再层序遍历输出结点的值即可 这里使用输出保存树的结点,结点的结构体为值、位置、左右孩子的位置 #include<cstdio> #include<queue> #in 阅读全文
posted @ 2020-09-12 15:40 是水泵呢 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 题意:给定n个数构建完全二叉树,输出完全二叉树的层序遍历 思路:二叉树的中序遍历建树即为输出 #include<cstdio> #include<queue> #include<vector> #include<algorithm> using namespace std; const int N 阅读全文
posted @ 2020-09-12 15:16 是水泵呢 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 实现:深度优先搜索 class Solution { public: vector<vector<int>> combinationSum(vector<int>& candidates, int target) { DFS(0,0,target,candidates.size(),candidat 阅读全文
posted @ 2020-09-09 21:27 是水泵呢 阅读(138) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> #include<queue> #include<vector> using namespace std; const int N = 110; int n; struct node{ int layer; bool isleaf = true; vector<in 阅读全文
posted @ 2020-09-09 17:55 是水泵呢 阅读(62) 评论(0) 推荐(0) 编辑
摘要: 层序遍历进行layer的确定 #include<cstdio> #include<vector> #include<math.h> #include<queue> using namespace std; const int N = 100010; const int INF = 100010; i 阅读全文
posted @ 2020-09-09 17:37 是水泵呢 阅读(83) 评论(0) 推荐(0) 编辑