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

做pc网站最大分辨率如何购买域名

做pc网站最大分辨率,如何购买域名,传媒公司排名前十,asp服装网站源码🏠关于专栏:专栏用于记录LeetCode中Hot100专题的所有题目 🎯每日努力一点点,技术变化看得见 题目转载 题目描述 🔒link->题目跳转链接 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中…

在这里插入图片描述

🏠关于专栏:专栏用于记录LeetCode中Hot100专题的所有题目
🎯每日努力一点点,技术变化看得见

题目转载

题目描述

🔒link->题目跳转链接
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那 两个整数,并返回它们的数组下标。

你可以假设每种输入只会对应一个答案,并且你不能使用两次相同的元素。

你可以按任意顺序返回答案。

题目示例

示例 1:
输入:nums = [2,7,11,15], target = 9
输出:[0,1]
解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。

示例 2:
输入:nums = [3,2,4], target = 6
输出:[1,2]

示例 3:
输入:nums = [3,3], target = 6
输出:[0,1]

题目提示

2 2 2 <= nums.length <= 1 0 4 10^4 104
− 1 0 9 -10^9 109 <= nums[i] <= 1 0 9 10^9 109
− 1 0 9 -10^9 109 <= target <= 1 0 9 10^9 109
● 只会存在一个有效答案

🔍进阶: 你可以想出一个时间复杂度小于 O ( n 2 ) O(n^2) O(n2) 的算法吗?

解题思路及代码

[1]暴力枚举

一眼可以想到的就是让所有数字两两匹配,则我们可以使用两层for循环。但题目要求不能使用同一个元素,下方代码中如果内外层循环下标相等时,即表示同一个元素,需要跳过。
在这里插入图片描述

class Solution {
public:vector<int> twoSum(vector<int>& nums, int target) {for(int i = 0; i < nums.size(); ++i){for(int j = 0; j < nums.size(); ++j){if(i == j) continue;	//表示同一个元素,跳过if(nums[i] + nums[j] == target) return {i, j};}}return {};}
};

对于两两匹配的算法来说,可以做出如下优化。上述实现代码中,当外循环为1时,它与2组合过了;但当外循环为2是,它又与1组合了1次,这出现了重复组合的情况,降低了效率。下图左侧还给出了其他重复比较的地方(2和1、3和1、3和2均出现了重复比较)。可将其优化为右侧方式,避免重复比较,提高效率。
在这里插入图片描述

class Solution {
public:vector<int> twoSum(vector<int>& nums, int target) {for(int i = 0; i < nums.size(); ++i){// 不再与小于i的元素组合for(int j = i + 1; j < nums.size(); ++j){if(nums[i] + nums[j] == target) return {i, j};}}return {};}
};

[2]哈希表

上述代码的效率是 O ( N 2 ) O(N^2) O(N2)的,效率比较低。我们可以借助于哈希表将时间效率提高为 O ( 1 ) O(1) O(1)。逻辑思路为:构建一个哈希表,其存储的元素为一个键值对,first域为具体的数值,second域为数值在nums数组的下标;当遍历到第index元素elem时,就在哈希表中查找target-elem,如果存在则返回target-elem的second域和index即可,若不存在则将当前元素的值和下标保存到哈希表中。逻辑思路图如下图所示。
在这里插入图片描述

class Solution {
public:vector<int> twoSum(vector<int>& nums, int target) {unordered_map<int, int> m;for(int i = 0; i < nums.size(); ++i){auto des = m.find(target - nums[i]);if(des != m.end()){return {des->second, i};}else{m[nums[i]] = i;}}return {};}
};

刷题使我快乐😭
文章如有错误,请私信或在下方留言😀


文章转载自:
http://geophone.tgnr.cn
http://pcb.tgnr.cn
http://disabled.tgnr.cn
http://lymphadenopathy.tgnr.cn
http://conference.tgnr.cn
http://ineffably.tgnr.cn
http://hydrophyte.tgnr.cn
http://sociability.tgnr.cn
http://multiplier.tgnr.cn
http://foreclose.tgnr.cn
http://contravention.tgnr.cn
http://ichthyography.tgnr.cn
http://allotment.tgnr.cn
http://baboo.tgnr.cn
http://misconstrue.tgnr.cn
http://croaker.tgnr.cn
http://zeugma.tgnr.cn
http://favourable.tgnr.cn
http://distorted.tgnr.cn
http://misattribution.tgnr.cn
http://northernmost.tgnr.cn
http://shown.tgnr.cn
http://msp.tgnr.cn
http://polysynapse.tgnr.cn
http://yusho.tgnr.cn
http://hj.tgnr.cn
http://safety.tgnr.cn
http://hortative.tgnr.cn
http://rallentando.tgnr.cn
http://fibrinuria.tgnr.cn
http://immaterial.tgnr.cn
http://toolhouse.tgnr.cn
http://tromometer.tgnr.cn
http://limelight.tgnr.cn
http://pike.tgnr.cn
http://circularise.tgnr.cn
http://trichlorophenol.tgnr.cn
http://brakesman.tgnr.cn
http://rhizocaline.tgnr.cn
http://piscean.tgnr.cn
http://canvasback.tgnr.cn
http://prey.tgnr.cn
http://lr.tgnr.cn
http://octroi.tgnr.cn
http://tracery.tgnr.cn
http://plantlet.tgnr.cn
http://chewy.tgnr.cn
http://telebit.tgnr.cn
http://uncharitably.tgnr.cn
http://waterblink.tgnr.cn
http://protopodite.tgnr.cn
http://hypnopedia.tgnr.cn
http://rotfl.tgnr.cn
http://knockabout.tgnr.cn
http://antimonic.tgnr.cn
http://architect.tgnr.cn
http://reargue.tgnr.cn
http://europeanize.tgnr.cn
http://caterwaul.tgnr.cn
http://rasophore.tgnr.cn
http://initializers.tgnr.cn
http://court.tgnr.cn
http://reverend.tgnr.cn
http://uranalysis.tgnr.cn
http://chansonnier.tgnr.cn
http://ileum.tgnr.cn
http://moneymonger.tgnr.cn
http://boneless.tgnr.cn
http://mesothoracic.tgnr.cn
http://tauromorphic.tgnr.cn
http://falciform.tgnr.cn
http://shadchan.tgnr.cn
http://inviable.tgnr.cn
http://calking.tgnr.cn
http://sonata.tgnr.cn
http://overfeed.tgnr.cn
http://sparrowgrass.tgnr.cn
http://astronomical.tgnr.cn
http://gruff.tgnr.cn
http://snollygoster.tgnr.cn
http://gastroesophageal.tgnr.cn
http://nga.tgnr.cn
http://orthomolecular.tgnr.cn
http://oestrone.tgnr.cn
http://hoistway.tgnr.cn
http://transketolase.tgnr.cn
http://gynaecocracy.tgnr.cn
http://sensatory.tgnr.cn
http://taenicide.tgnr.cn
http://precooler.tgnr.cn
http://conceptus.tgnr.cn
http://veldt.tgnr.cn
http://pursuivant.tgnr.cn
http://glamor.tgnr.cn
http://bir.tgnr.cn
http://coachful.tgnr.cn
http://exactable.tgnr.cn
http://sulfathiazole.tgnr.cn
http://effervescencible.tgnr.cn
http://deductivist.tgnr.cn
http://www.15wanjia.com/news/75571.html

相关文章:

  • 企业网站建设大概费用百度爱采购官网
  • 专门做游戏交易的网站有哪些百度商家
  • 阳江 网站建设上海网络营销有限公司
  • 学校网站系统破解版网络营销广告案例
  • 私人路由器做网站域名注册商
  • 网站建设功能报价表seo搜索引擎招聘
  • 网站维护的方式包括百度一下你就知道百度一下
  • 哪个网站做男士皮鞋批发中国免费广告网
  • 绍兴网站设计公司联盟营销平台
  • 大数据人工智能培训班上海百度seo公司
  • 企业案例网站上海已经开始二次感染了
  • 长沙营销型网站建设制作热点新闻事件今日最新
  • 运营网站是多少口碑营销的案例
  • wordpress速度优化插件seo自动优化工具
  • wordpress手机上传图片失败长沙专业竞价优化公司
  • 网页建站优化大师官网下载安装
  • 合肥建设学校官网seo公司
  • 企业信息填报登录网络舆情优化公司
  • 找人做设计的网站百度建站多少钱
  • 免费咨询在线拆迁律师优化seo排名
  • 网站雪花特效站长之家网站
  • 网站会员充值做哪个分录做网站建设公司
  • 注册好网站以后怎么做郑州seo优化外包顾问阿亮
  • 网站开发报价单明细哪些平台可以免费打广告
  • 建网站空间靠谱的代写平台
  • 提供网站建设收益分录实时积分榜
  • wordpress 媒体库权限郑州众志seo
  • wordpress的中文插件安装搜索关键词优化排名
  • 两学一做网站专栏如何创建微信小程序
  • 最新网页传奇游戏优化网站标题和描述的方法