摘要: 题目链接:https://leetcode-cn.com/problems/subarray-product-less-than-k/ 个人题解:滑动窗口+双指针 用 \(i\) 和 \(j\) 来维护滑动窗口的两端。 用 \(j\) 去遍历,同时维护 \(sum\) ,然后遍历 \(i\) ,去更 阅读全文
posted @ 2022-05-05 10:55 黑VS白-清墨 阅读(27) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/ 个人题解:开一个数组,从头到尾遍历,然后反转数组即可 代码: class Solution { public: vector<int> 阅读全文
posted @ 2022-05-04 11:44 黑VS白-清墨 阅读(27) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/find-the-winner-of-the-circular-game/ 个人题解: 队列模拟(会比较慢) 数学递归,迭代节省空间(对比约瑟夫环) 点击查看代码 class Solution { public: int f 阅读全文
posted @ 2022-05-04 11:04 黑VS白-清墨 阅读(21) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/ 个人题解:双栈,一个当作,一个当作输出。 将一个栈当作输入栈,用于压入数,另一个栈当作输出栈,用于弹出数。 当我们需要删除时 \(d 阅读全文
posted @ 2022-05-03 23:07 黑VS白-清墨 阅读(24) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/reorder-data-in-log-files/ 个人题解: 根据题意:数字日志 应该保留原来的相对顺序。因此要采用 \(stableSort()\) 函数 根据题目意思模拟即可 点击查看代码 class Solutio 阅读全文
posted @ 2022-05-03 01:38 黑VS白-清墨 阅读(21) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees/ 个人题解:中序遍历+排序 点击查看代码 /** * Definition for a binary tree node. * struct T 阅读全文
posted @ 2022-05-01 09:06 黑VS白-清墨 阅读(26) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode-cn.com/problems/merge-sorted-array/ 个人题解: 因为要求要用更高阶的算法,时间复杂度为 \(O(m+n)\),因此用双指针进行优化 采用线性合并的方法: 时间复杂度 \(O(m+n)\) ,空间复杂度 \(O(1 阅读全文
posted @ 2022-04-21 20:49 黑VS白-清墨 阅读(107) 评论(0) 推荐(0)
摘要: 三道题 第一题 题目链接:https://leetcode-cn.com/problems/add-strings/ 个人题解:大整数相加板子题 点击查看代码 class Solution { public: vector<int> add(vector<int>& A, vector<int>& 阅读全文
posted @ 2022-04-20 17:23 黑VS白-清墨 阅读(55) 评论(0) 推荐(0)
摘要: 三道题 第一题 题目链接:https://leetcode-cn.com/problems/first-missing-positive/ 个人题解: 不用额外空间的桶排序: 保证 \(1\) 出现在 \(nums[0]\) 的位置上,..., \(n\) 出现在 \(nums[n-1]\) 的位置 阅读全文
posted @ 2022-04-19 13:59 黑VS白-清墨 阅读(80) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode-cn.com/problems/remove-element/ 个人题解:因为要原地修改数组,所以要双指针。从前往后遍历一遍即可 代码: class Solution { public: int removeElement(vector<int>& 阅读全文
posted @ 2022-04-18 16:05 黑VS白-清墨 阅读(69) 评论(0) 推荐(0)