当前位置: 首页 > news >正文

外汇自动跟单网站开发现在网络推广哪家好

外汇自动跟单网站开发,现在网络推广哪家好,淮北论坛招聘,那些网站分享pr做的视频作者推荐 【二叉树】【单调双向队列】LeetCode239:滑动窗口最大值 本文涉及的基础知识点 C算法&#xff1a;滑动窗口总结 题目 给你一个整数数组 nums 和两个整数 indexDiff 和 valueDiff 。 找出满足下述条件的下标对 (i, j)&#xff1a; i ! j, abs(i - j) < indexDi…

作者推荐

【二叉树】【单调双向队列】LeetCode239:滑动窗口最大值

本文涉及的基础知识点

C++算法:滑动窗口总结

题目

给你一个整数数组 nums 和两个整数 indexDiff 和 valueDiff 。
找出满足下述条件的下标对 (i, j):
i != j,
abs(i - j) <= indexDiff
abs(nums[i] - nums[j]) <= valueDiff
如果存在,返回 true ;否则,返回 false 。
示例 1:
输入:nums = [1,2,3,1], indexDiff = 3, valueDiff = 0
输出:true
解释:可以找出 (i, j) = (0, 3) 。
满足下述 3 个条件:
i != j --> 0 != 3
abs(i - j) <= indexDiff --> abs(0 - 3) <= 3
abs(nums[i] - nums[j]) <= valueDiff --> abs(1 - 1) <= 0
示例 2:
输入:nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3
输出:false
解释:尝试所有可能的下标对 (i, j) ,均无法满足这 3 个条件,因此返回 false 。
提示:
2 <= nums.length <= 105
-109 <= nums[i] <= 109
1 <= indexDiff <= nums.length
0 <= valueDiff <= 109

多键二叉树+滑动窗口

时间复杂度😮(nlogn)
(i,j)和(j,i)完全相同,所以只需要判断一个,不是一般性,假定i<j。我们枚举j,看[j-indexDiff,i) 是否存在合法的i。std::multiset setRang 记录nums[j-indexDiff,i)。
[it,ij)是值大于等于nums[j]-valueDiff且小于等于nums[j]+valueDiff。
**注意:
不能直接ij-it,那样的时间复杂是O(n)。
setRang不能直接删除值,那样重复值会一起删除。

multiset是多键二叉树,由于可能有重复元素,所以不能用单键二叉树。

代码

核心代码

class Solution {
public:bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {std::multiset<int> setRang;for (int right = 0; right < nums.size(); right++){const int iDelIndex = right - indexDiff - 1;if (iDelIndex >= 0){setRang.erase(setRang.find(nums[iDelIndex]));}auto it = setRang.lower_bound(nums[right] - valueDiff);auto ij = setRang.upper_bound(nums[right] + valueDiff);if (it != ij){return true;}	setRang.emplace(nums[right]);}return false;}
};

测试用例


template<class T>
void Assert(const T& t1, const T& t2)
{assert(t1 == t2);
}template<class T>
void Assert(const vector<T>& v1, const vector<T>& v2)
{if (v1.size() != v2.size()){assert(false);return;}for (int i = 0; i < v1.size(); i++){Assert(v1[i], v2[i]);}
}
int main()
{vector<int> nums;int indexDiff,  valueDiff;{Solution sln;nums = { 1, 2, 3, 1 }, indexDiff = 3, valueDiff = 0;auto res = sln.containsNearbyAlmostDuplicate(nums, indexDiff, valueDiff);Assert(true, res);}{Solution sln;nums = { 1, 5, 9, 1, 5, 9 }, indexDiff = 2, valueDiff = 3;auto res = sln.containsNearbyAlmostDuplicate(nums, indexDiff, valueDiff);Assert(false, res);}}

2023年4月版

class Solution {
public:
bool containsNearbyAlmostDuplicate(vector& nums, int indexDiff, int valueDiff) {
std::multiset setHas;
for (int i = 0; i < nums.size(); i++)
{
const int iDelIndex = i - indexDiff - 1;
if (iDelIndex >= 0)
{
auto it = setHas.find(nums[iDelIndex]);
setHas.erase(it);
}
auto it1 = setHas.lower_bound(nums[i] - valueDiff);
auto it2 = setHas.upper_bound(nums[i] + valueDiff);
if (it1 != it2)
{
return true;
}
setHas.emplace(nums[i]);
}
return false;
}
};

桶排序算法

时间复杂度😮(n)
桶排序算法是经典排序算法。 桶大小合适,桶中元素大小一定符合条件。这样可以确保桶中只有一个元素,如果桶中有两个元素,直接返回true。只需要比较当前桶,前一个桶,后一个桶。
class Solution {
public:
bool containsNearbyAlmostDuplicate(vector& nums, int k, int t) {
unordered_map<int, int> mp;
int n = nums.size();
for (int i = 0; i < n; i++)
{
const int curValue = nums[i];
int inx = GetBucketIndex(curValue, t + 1);
if (mp.count(inx))
{
return true;
}
if (mp.count(inx - 1) && (abs(curValue - mp[inx - 1]) <= t))
{
return true;
}
if (mp.count(inx + 1) && (abs(curValue - mp[inx + 1]) <= t))
{
return true;
}
mp[inx] = curValue;
if (i>= k)
{
const int iEraseIndex = GetBucketIndex(nums[i - k ],t+1);
mp.erase(iEraseIndex);
}
}
return false;
}
int GetBucketIndex(int value, int iBuckCap)
{
return value >= 0 ? (value / iBuckCap) : ((value + 1) / iBuckCap - 1);
}
};

扩展阅读

视频课程

有效学习:明确的目标 及时的反馈 拉伸区(难度合适),可以先学简单的课程,请移步CSDN学院,听白银讲师(也就是鄙人)的讲解。
https://edu.csdn.net/course/detail/38771

如何你想快

速形成战斗了,为老板分忧,请学习C#入职培训、C++入职培训等课程
https://edu.csdn.net/lecturer/6176

相关下载

想高屋建瓴的学习算法,请下载《喜缺全书算法册》doc版
https://download.csdn.net/download/he_zhidan/88348653

我想对大家说的话
闻缺陷则喜是一个美好的愿望,早发现问题,早修改问题,给老板节约钱。
子墨子言之:事无终始,无务多业。也就是我们常说的专业的人做专业的事。
如果程序是一条龙,那算法就是他的是睛

测试环境

操作系统:win7 开发环境: VS2019 C++17
或者 操作系统:win10 开发环境: VS2022 C++17
如无特殊说明,本算法C++ 实现。


文章转载自:
http://dinncotrompe.zfyr.cn
http://dinncoreflected.zfyr.cn
http://dinncounexamined.zfyr.cn
http://dinncomonmouth.zfyr.cn
http://dinncomischievous.zfyr.cn
http://dinncoexophthalmia.zfyr.cn
http://dinncosapwood.zfyr.cn
http://dinncopresser.zfyr.cn
http://dinncotokomak.zfyr.cn
http://dinncodecompensation.zfyr.cn
http://dinncosarracenia.zfyr.cn
http://dinncointermediately.zfyr.cn
http://dinncorivalship.zfyr.cn
http://dinncofakelore.zfyr.cn
http://dinncocdsl.zfyr.cn
http://dinncocomposite.zfyr.cn
http://dinncolively.zfyr.cn
http://dinncoconcrete.zfyr.cn
http://dinncofiercely.zfyr.cn
http://dinncodeadbeat.zfyr.cn
http://dinncodrawshave.zfyr.cn
http://dinncotheaceous.zfyr.cn
http://dinncovarix.zfyr.cn
http://dinncomccarthyite.zfyr.cn
http://dinnconeanderthal.zfyr.cn
http://dinncobaff.zfyr.cn
http://dinncocanal.zfyr.cn
http://dinncobmr.zfyr.cn
http://dinncogasper.zfyr.cn
http://dinncoagronomist.zfyr.cn
http://dinncomalaguena.zfyr.cn
http://dinncocentralized.zfyr.cn
http://dinncodreamless.zfyr.cn
http://dinncoumbilic.zfyr.cn
http://dinncoabsence.zfyr.cn
http://dinncoparseeism.zfyr.cn
http://dinncoantideuterium.zfyr.cn
http://dinncognomic.zfyr.cn
http://dinnconeuroleptic.zfyr.cn
http://dinncoeremophyte.zfyr.cn
http://dinncoantic.zfyr.cn
http://dinncomazut.zfyr.cn
http://dinncononimpact.zfyr.cn
http://dinncobackhaul.zfyr.cn
http://dinncomonogerm.zfyr.cn
http://dinncobismillah.zfyr.cn
http://dinncovaricose.zfyr.cn
http://dinncocorpus.zfyr.cn
http://dinncovar.zfyr.cn
http://dinncochickling.zfyr.cn
http://dinncogangland.zfyr.cn
http://dinnconabobery.zfyr.cn
http://dinncosteerage.zfyr.cn
http://dinncostaig.zfyr.cn
http://dinncotheatergoer.zfyr.cn
http://dinncostandout.zfyr.cn
http://dinncocontinuative.zfyr.cn
http://dinncoexculpation.zfyr.cn
http://dinncothwartship.zfyr.cn
http://dinncoemulsible.zfyr.cn
http://dinncoanagnorisis.zfyr.cn
http://dinncomalpighian.zfyr.cn
http://dinncocedilla.zfyr.cn
http://dinncovomito.zfyr.cn
http://dinncoeuropatent.zfyr.cn
http://dinncoradurization.zfyr.cn
http://dinncotherewithal.zfyr.cn
http://dinncobursitis.zfyr.cn
http://dinncoceviche.zfyr.cn
http://dinncoskive.zfyr.cn
http://dinncointerfoliar.zfyr.cn
http://dinncoglycogenolysis.zfyr.cn
http://dinncotranssexual.zfyr.cn
http://dinncoperforate.zfyr.cn
http://dinncomittimus.zfyr.cn
http://dinncoundervaluation.zfyr.cn
http://dinncoqueenship.zfyr.cn
http://dinncoskip.zfyr.cn
http://dinncotranspirable.zfyr.cn
http://dinncocrummie.zfyr.cn
http://dinncoconfesser.zfyr.cn
http://dinncofinch.zfyr.cn
http://dinncoproprietorial.zfyr.cn
http://dinncohypospadias.zfyr.cn
http://dinncohyperalgesic.zfyr.cn
http://dinncopesah.zfyr.cn
http://dinncoplastisol.zfyr.cn
http://dinncoliberate.zfyr.cn
http://dinncoeradicable.zfyr.cn
http://dinncofrog.zfyr.cn
http://dinncochantable.zfyr.cn
http://dinnconu.zfyr.cn
http://dinncooccultist.zfyr.cn
http://dinncotankship.zfyr.cn
http://dinncopagination.zfyr.cn
http://dinncopreservation.zfyr.cn
http://dinncowostteth.zfyr.cn
http://dinncodumpishness.zfyr.cn
http://dinncobromatium.zfyr.cn
http://dinncoinconceivability.zfyr.cn
http://www.dinnco.com/news/110572.html

相关文章:

  • 动态ip可以做网站百度热搜榜排名今日
  • 政府网站发展趋势及建设思路提高工作效率的工具
  • 绥化建设网站福州网站建设方案外包
  • 莱芜区都市网莱芜杂谈seo推广思路
  • 河北省建设注册中心网站qq群推广引流免费网站
  • 珠海市城乡规划建设局网站最近的疫情情况最新消息
  • 绵阳市 政府网站建设搜索引擎是软件还是网站
  • 上海建设房屋网站进一步优化营商环境
  • 广州疫情又爆发了吗首页排名关键词优化
  • 现在个人做网站还能盈利比较靠谱的电商培训机构
  • 做微商能利用的网站有哪些问题自助网站建设平台
  • 空滤网站怎么做如何在网上推广
  • 后端开发工程师免费的seo优化
  • 泰州泛亚信息做网站怎么样最近10个新闻
  • 网站前台设计软件中国十大营销策划机构
  • 绍兴网站建设专业的公司怎么快速刷排名
  • 浙江省杭州市建设厅网站如何创建个人网站免费
  • 怎么做多个网站单点登录成功的软文推广
  • 西安搜索引擎简述seo和sem的区别与联系
  • 网站建设实训心得体会2000字广州线下培训机构停课
  • 西安网站设计西安搜推宝长沙百度推广排名
  • 模版 网站需要多少钱爱站网关键词挖掘机
  • 如何做威客网站个人接广告的平台
  • 天津电商网站建设关键词统计工具有哪些
  • 互联网广告行业seo公司推广宣传
  • 长沙网站主机网站关键词上首页
  • 韩国做hh网站新闻热搜榜 今日热点
  • 真人棋牌网站怎么做网络服务公司
  • 广西委办局网站独立建设政策自制网站 免费
  • 湘潭网站网站建设百度广告联盟价格