LeetCode82 删除排序链表中的重复元素II 题目描述 给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字。 样例 输入: 1->2->3->3->4->4->5 输出: 1->2->5 输入: 1->1->1->2->3 输出: 2->3 算法分析 时间复杂 ...
分类:
编程语言 时间:
2020-11-24 12:38:37
阅读次数:
6
Difficulty: Medium Related Topics: Depth-first Search, Breadth-first Search, Union Find Link: https://leetcode.com/problems/number-of-islands/ Descrip ...
分类:
其他好文 时间:
2020-11-23 12:25:21
阅读次数:
3
Link: https://www.luogu.com.cn/problem/P1903 Solution 这个 sort 我暂且蒙在鼓里 先贴个代码。 本来我 T 了三个点的 cmp 函数如下 bool cmp(const s_q &a, const s_q &b) { if (belong[a. ...
分类:
其他好文 时间:
2020-11-21 11:54:33
阅读次数:
4
简单动态规划:dp[i]是以位置i结束的最大和,动态转移方程dp[i] = max(dp[i-1]+array[i], array[i]),dp中的最大值即是结果。 class Solution { public: int FindGreatestSumOfSubArray(vector<int> ...
分类:
编程语言 时间:
2020-11-21 11:46:10
阅读次数:
5
leetcode(daily 11-8 ~ 11-14) leetcode 每日一题 11-8 122. 买卖股票的最佳时机 II class Solution { public int maxProfit(int[] prices) { // 贪心算法:只要今天买明天赚就买入 // profit用 ...
分类:
其他好文 时间:
2020-11-20 12:09:49
阅读次数:
9
题目链接:https://leetcode-cn.com/problems/relative-sort-array/ 又是一个简单题,懒得多说了,我用的暴力,有价值的地方就是题解用的这种自定义排序的方法, 之前没写过这样的自定义排序,码住。 class Solution { public: vect ...
分类:
编程语言 时间:
2020-11-19 12:44:37
阅读次数:
7
因为子数组是连续的,所以判断连续的子数组的和时,我们往往开一个前缀和数组预处理出所有数的前缀和,这样能够降低求子数组的和的时间复杂度。 这题需要单独处理k为0的情况,由于数组所有元素都是非负数,所以当k为0时,如果存在两个相邻的数的值都为0,则返回true,否则返回false。 使用前缀和判断是否存 ...
分类:
编程语言 时间:
2020-11-19 12:34:32
阅读次数:
7
思路 方法一:暴力法 遍历每一个数nums[i],之后在[i, i+k]中顺序寻找最大值。 时间复杂度:O(k*n) 1 class Solution { 2 public: 3 vector<int> maxSlidingWindow(vector<int>& nums, int k) { 4 i ...
分类:
其他好文 时间:
2020-11-19 12:32:53
阅读次数:
6
思路 方法一:二分 遍历每个数字num,然后再在后面的数字中使用二分查找target-num。 复杂度分析 时间复杂度:O(nlogn) 空间复杂度:O(1) 1 class Solution { 2 public: 3 vector<int> twoSum(vector<int>& nums, i ...
分类:
其他好文 时间:
2020-11-19 12:17:07
阅读次数:
4
\(Link\) Description 给一个长度为$n$的数列和$m$,在数列任选若干个数,使得他们的和对$m$取模后最大。 \(n ≤ 35, 1 ≤ m ≤ 10^9\) Solution $n$这么小,一看就知道要爆搜。但纯搜索是$O(2^n)$的,跑不过去。这时可以考虑$Meet\ in ...
分类:
其他好文 时间:
2020-11-19 12:16:10
阅读次数:
5