leetcode/牛客
文章平均质量分 54
leetcode/牛客
华-山
这个作者很懒,什么都没留下…
展开
-
关于set中使用lower_bound 和 upper_bound 的时间复杂度
在刷力扣上220. 存在重复元素 III的题目遇到了一个问题,原题目如下:最开始的思路是维护一个最大长度为 k 的滑动窗口,窗口元素放在有序集合中,然后二分查找有序集合中是否有满足条件的元素。代码如下(超时了):class Solution {public: bool check(multiset<int> &st, long target, long t) { auto p = lower_bound(st.begin(), st.e..原创 2021-04-17 10:52:44 · 4704 阅读 · 0 评论 -
C++ 线程同步操作的几种方法 【LeetCode 1115. 交替打印FooBar】
题目如下:原程序如下,我们需要基于原程序进行修改:class FooBar {private: int n;public: FooBar(int n) { this->n = n; } void foo(function<void()> printFoo) { for (int i = 0; i < n; i++) { // printF原创 2021-04-13 22:18:52 · 281 阅读 · 0 评论 -
leetcode[76. 最小覆盖子串] 引发的关于变量出栈入栈的思考
原题给你一个字符串 s 、一个字符串 t 。返回 s 中涵盖 t 所有字符的最小子串。如果 s 中不存在涵盖 t 所有字符的子串,则返回空字符串 "" 。注意:如果 s 中存在这样的子串,我们保证它是唯一的答案。刚看到这题第一反应是使用滑动窗口+hashmap内部判断滑动窗口是否满足条件。于是码完代码测试后提交,发现超时。代码如下:class Solution {public: bool check(unordered_map<char, int> org, un原创 2021-02-03 23:36:59 · 145 阅读 · 0 评论