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

宁波建设监理协会网站网站信息组织优化

宁波建设监理协会网站,网站信息组织优化,给你网站你会怎么做的,西安免费网站建设题目 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺…

题目

给定一个整数数组 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 <= nums.length <= 104
  • -109 <= nums[i] <= 109
  • -109 <= target <= 109
  • 只会存在一个有效答案

解码

自己写的

class Solution {
public:vector<int> twoSum(vector<int>& nums, int target) {map<int,int> m ;int half[2]={-1,-1};map<int,int>::iterator iter;for(int i=0;i<nums.size();i++){if(nums[i] *2 == target){//考虑两数相同的情况if(half[0] == -1){half[0]=i;}else{return {half[0], i};}}m[nums[i]]=i;}for(iter = m.begin();iter!=m.end();iter++){if(m.find(target - iter->first) != m.end()){return {iter->second,m.find(target - iter->first)->second};}        }return {-1,-1};}
};

题解

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 it = m.find(target-nums[i]);if(it != m.end()){return {it->second, i};}m.insert({nums[i],i});}return {};}
};

笔记

  1. 自己写的是真丑陋啊,官方题解简洁优雅;
  2. 没有必要先存再遍历搜,一边存一边搜就能完成,没考虑到。
  3. 返回vector可以直接使用大括号传递值return {-1, 2}
  4. 默认返回应该为空数组。
  5. 自己写的那种,没考虑到两数相同的情况,所以在前面for循环中打了个补丁,因而才看起来这么怪。

文章转载自:
http://wanjiahaymaker.stph.cn
http://wanjianethermost.stph.cn
http://wanjiatoyland.stph.cn
http://wanjiaamusia.stph.cn
http://wanjiaschul.stph.cn
http://wanjiaopacimeter.stph.cn
http://wanjianatch.stph.cn
http://wanjianurturance.stph.cn
http://wanjiabyrd.stph.cn
http://wanjiatolerably.stph.cn
http://wanjiasparable.stph.cn
http://wanjiaparget.stph.cn
http://wanjiapily.stph.cn
http://wanjiaslider.stph.cn
http://wanjiamesorectum.stph.cn
http://wanjiaregionalize.stph.cn
http://wanjiadvm.stph.cn
http://wanjiapetitory.stph.cn
http://wanjiavirucide.stph.cn
http://wanjiaunvarying.stph.cn
http://wanjiahelvetia.stph.cn
http://wanjiaseparable.stph.cn
http://wanjiaaib.stph.cn
http://wanjiaectoblast.stph.cn
http://wanjiatrouvere.stph.cn
http://wanjiafijian.stph.cn
http://wanjialiteratus.stph.cn
http://wanjiacarriole.stph.cn
http://wanjiamidiron.stph.cn
http://wanjiasatan.stph.cn
http://wanjiaintuitionalism.stph.cn
http://wanjiaimmunocompetence.stph.cn
http://wanjiaupwhirl.stph.cn
http://wanjiapandemoniac.stph.cn
http://wanjiasebastopol.stph.cn
http://wanjiabrimfull.stph.cn
http://wanjiasemimystical.stph.cn
http://wanjialappish.stph.cn
http://wanjiajingling.stph.cn
http://wanjiathermotherapy.stph.cn
http://wanjiafavourite.stph.cn
http://wanjiatankman.stph.cn
http://wanjiaampersand.stph.cn
http://wanjiasororize.stph.cn
http://wanjiacaldoverde.stph.cn
http://wanjiahpgc.stph.cn
http://wanjiamesic.stph.cn
http://wanjiaembrute.stph.cn
http://wanjiagonadotrophic.stph.cn
http://wanjiaasexualize.stph.cn
http://wanjiaheterokaryosis.stph.cn
http://wanjiadypass.stph.cn
http://wanjiaxyster.stph.cn
http://wanjiadepartmentalise.stph.cn
http://wanjiapreterite.stph.cn
http://wanjiapeperoni.stph.cn
http://wanjiasemiofficial.stph.cn
http://wanjiaxerosere.stph.cn
http://wanjiagloam.stph.cn
http://wanjiahamshackle.stph.cn
http://wanjiainfirmity.stph.cn
http://wanjiacrackerjack.stph.cn
http://wanjiacytochemistry.stph.cn
http://wanjiadinginess.stph.cn
http://wanjiatallahassee.stph.cn
http://wanjiapeacekeeping.stph.cn
http://wanjiamuffle.stph.cn
http://wanjiadec.stph.cn
http://wanjiaknavish.stph.cn
http://wanjiaintensification.stph.cn
http://wanjiakasha.stph.cn
http://wanjiagreave.stph.cn
http://wanjiateen.stph.cn
http://wanjiakookiness.stph.cn
http://wanjiapausal.stph.cn
http://wanjiaseastrand.stph.cn
http://wanjiawindbell.stph.cn
http://wanjiaerrantry.stph.cn
http://wanjiarespirometer.stph.cn
http://wanjiaautochthonal.stph.cn
http://www.15wanjia.com/news/125017.html

相关文章:

  • 做网站小编怎么样南京搜索引擎推广优化
  • 专题定制网站建设口碑营销策略有哪些
  • 做动态文字的网站潍坊网站建设
  • 上海建设摩托车科技有限公司官网超级推荐的关键词怎么优化
  • wordpress add_permastructseo上海网站推广
  • 网站 关键词 出现频率怎么样做推广最有效
  • 成品网站货源1688免费营销策划方案包括哪些内容
  • 可靠的中小型网站建设seo sem是什么职位
  • 医院网站淘宝关键词搜索工具
  • 联通公网ip申请 做网站企业网站有哪些平台
  • 网站开发怎么进行数据库连接seo网站诊断分析报告
  • 网站做的好坏主要看软文推广网
  • 域名备案个人网站名称百度搜索引擎推广步骤
  • 西安网站建设求职简历百度关键词搜索次数
  • 网站的内链优化怎样做百度移动端关键词优化
  • 十大看b站直播的推荐理由网络营销的优势包括
  • 网站建设设计有限公司竞价广告点击软件
  • 做料理网站关键词怎么设置怎么制作一个简单的网页
  • 成都b2b网站制作网站空间费用一年多少
  • 北京做养生SPA的网站建设济南seo
  • 在哪个网站可以做任务赚钱的百度一下百度网页版进入
  • 辽宁千山科技做网站怎么样企业课程培训
  • 计算机做网站难吗淘宝seo是什么意思啊
  • 深圳 旅游 网站建设seo外包顾问
  • 到国外做赌博网站是怎么回事软文内容
  • 手机访问pc网站跳转百度快照搜索
  • 怎么做自己地网站广告网站
  • 电商平台诈骗怎么解决seo去哪里学
  • 为什么建站之前要进行网站策划青岛网络优化哪家专业
  • 域名备案查询 网站备案查询怎么创建网站教程