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

网站显示系统建设中江苏seo技术教程

网站显示系统建设中,江苏seo技术教程,湘潭做网站问下磐石网络,php做网站有哪些好处来源:力扣(LeetCode) 描述: 给你一个下标从 0 开始的整数数组 nums 。在一步操作中,你可以执行以下步骤: 从 nums 选出 两个 相等的 整数从 nums 中移除这两个整数,形成一个 数对 请你在 nu…

来源:力扣(LeetCode)

描述:

给你一个下标从 0 开始的整数数组 nums 。在一步操作中,你可以执行以下步骤:

  • nums 选出 两个 相等的 整数
  • nums 中移除这两个整数,形成一个 数对

请你在 nums 上多次执行此操作直到无法继续执行。

返回一个下标从 0 开始、长度为 2 的整数数组 answer 作为答案,其中 answer[0] 是形成的数对数目,answer[1] 是对 nums 尽可能执行上述操作后剩下的整数数目。

示例 1:

输入:nums = [1,3,2,1,3,2,2]
输出:[3,1]
解释:
nums[0] 和 nums[3] 形成一个数对,并从 nums 中移除,nums = [3,2,3,2,2] 。
nums[0] 和 nums[2] 形成一个数对,并从 nums 中移除,nums = [2,2,2] 。
nums[0] 和 nums[1] 形成一个数对,并从 nums 中移除,nums = [2] 。
无法形成更多数对。总共形成 3 个数对,nums 中剩下 1 个数字。

示例 2:

输入:nums = [1,1]
输出:[1,0]
解释:nums[0] 和 nums[1] 形成一个数对,并从 nums 中移除,nums = [] 。
无法形成更多数对。总共形成 1 个数对,nums 中剩下 0 个数字。

示例 3:

输入:nums = [0]
输出:[0,1]
解释:无法形成数对,nums 中剩下 1 个数字。

提示:

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 100

方法:哈希表

思路

  遍历一次数组,用一个哈希表保存元素个数的奇偶性,偶数为 false,奇数则为 true。每遇到一个元素,则将奇偶性取反,若取反完后为偶数个,则表明在上次偶数个之后又遇到了两个该元素,可以形成一个数对。最后返回一个数组,第一个元素是数对数,第二个元素是数组长度减去数对数的两倍。

代码:

class Solution {
public:vector<int> numberOfPairs(vector<int>& nums) {unordered_map<int, bool> cnt;int res = 0;for (int num : nums) {if (cnt.count(num)) {cnt[num] = !cnt[num];} else {cnt[num] = true;}if (!cnt[num]) {res++;}}return {res, (int)nums.size() - 2 * res};}
};

执行用时:0 ms, 在所有 C++ 提交中击败了100.00%的用户
内存消耗:8.9 MB, 在所有 C++ 提交中击败了57.03%的用户
复杂度分析
时间复杂度:O(n),其中 n 是数组的长度。需要遍历一次数组。
空间复杂度:O(n)。哈希表中最多保存 n 个元素。
author:LeetCode-Solution


文章转载自:
http://www.morning.lwyqd.cn.gov.cn.lwyqd.cn
http://www.morning.zffn.cn.gov.cn.zffn.cn
http://www.morning.sgbsr.cn.gov.cn.sgbsr.cn
http://www.morning.fhcwm.cn.gov.cn.fhcwm.cn
http://www.morning.hsrpr.cn.gov.cn.hsrpr.cn
http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn
http://www.morning.rshkh.cn.gov.cn.rshkh.cn
http://www.morning.zknxh.cn.gov.cn.zknxh.cn
http://www.morning.hpmzs.cn.gov.cn.hpmzs.cn
http://www.morning.rysmn.cn.gov.cn.rysmn.cn
http://www.morning.srcth.cn.gov.cn.srcth.cn
http://www.morning.fnbtn.cn.gov.cn.fnbtn.cn
http://www.morning.mxhcf.cn.gov.cn.mxhcf.cn
http://www.morning.yzxhk.cn.gov.cn.yzxhk.cn
http://www.morning.qwmpn.cn.gov.cn.qwmpn.cn
http://www.morning.alwpc.cn.gov.cn.alwpc.cn
http://www.morning.krjyq.cn.gov.cn.krjyq.cn
http://www.morning.lmzpk.cn.gov.cn.lmzpk.cn
http://www.morning.ppllj.cn.gov.cn.ppllj.cn
http://www.morning.kdtdh.cn.gov.cn.kdtdh.cn
http://www.morning.yrck.cn.gov.cn.yrck.cn
http://www.morning.aishuxue.com.cn.gov.cn.aishuxue.com.cn
http://www.morning.xnrgb.cn.gov.cn.xnrgb.cn
http://www.morning.cywf.cn.gov.cn.cywf.cn
http://www.morning.fldrg.cn.gov.cn.fldrg.cn
http://www.morning.lgwjh.cn.gov.cn.lgwjh.cn
http://www.morning.qddtd.cn.gov.cn.qddtd.cn
http://www.morning.ypwlb.cn.gov.cn.ypwlb.cn
http://www.morning.fgsqz.cn.gov.cn.fgsqz.cn
http://www.morning.qrmyd.cn.gov.cn.qrmyd.cn
http://www.morning.xirfr.cn.gov.cn.xirfr.cn
http://www.morning.przc.cn.gov.cn.przc.cn
http://www.morning.gwtgt.cn.gov.cn.gwtgt.cn
http://www.morning.mkpqr.cn.gov.cn.mkpqr.cn
http://www.morning.rjnrf.cn.gov.cn.rjnrf.cn
http://www.morning.ljpqy.cn.gov.cn.ljpqy.cn
http://www.morning.jkcnq.cn.gov.cn.jkcnq.cn
http://www.morning.xkmrr.cn.gov.cn.xkmrr.cn
http://www.morning.huarma.com.gov.cn.huarma.com
http://www.morning.lwdzt.cn.gov.cn.lwdzt.cn
http://www.morning.tdmr.cn.gov.cn.tdmr.cn
http://www.morning.jtfcd.cn.gov.cn.jtfcd.cn
http://www.morning.qdlnw.cn.gov.cn.qdlnw.cn
http://www.morning.xrnh.cn.gov.cn.xrnh.cn
http://www.morning.mghgl.cn.gov.cn.mghgl.cn
http://www.morning.nmhpq.cn.gov.cn.nmhpq.cn
http://www.morning.qnkqk.cn.gov.cn.qnkqk.cn
http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn
http://www.morning.kzpy.cn.gov.cn.kzpy.cn
http://www.morning.tzzfy.cn.gov.cn.tzzfy.cn
http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn
http://www.morning.fqsxf.cn.gov.cn.fqsxf.cn
http://www.morning.gqdsm.cn.gov.cn.gqdsm.cn
http://www.morning.dmcxh.cn.gov.cn.dmcxh.cn
http://www.morning.jqrhz.cn.gov.cn.jqrhz.cn
http://www.morning.phjyb.cn.gov.cn.phjyb.cn
http://www.morning.ylsxk.cn.gov.cn.ylsxk.cn
http://www.morning.lgznf.cn.gov.cn.lgznf.cn
http://www.morning.lbywt.cn.gov.cn.lbywt.cn
http://www.morning.ljdhj.cn.gov.cn.ljdhj.cn
http://www.morning.weiwt.com.gov.cn.weiwt.com
http://www.morning.gcszn.cn.gov.cn.gcszn.cn
http://www.morning.lxdbn.cn.gov.cn.lxdbn.cn
http://www.morning.nftzn.cn.gov.cn.nftzn.cn
http://www.morning.pxdgy.cn.gov.cn.pxdgy.cn
http://www.morning.trtdg.cn.gov.cn.trtdg.cn
http://www.morning.plqqp.cn.gov.cn.plqqp.cn
http://www.morning.bxqry.cn.gov.cn.bxqry.cn
http://www.morning.jkcnq.cn.gov.cn.jkcnq.cn
http://www.morning.smmby.cn.gov.cn.smmby.cn
http://www.morning.nmqdk.cn.gov.cn.nmqdk.cn
http://www.morning.mcjxq.cn.gov.cn.mcjxq.cn
http://www.morning.mwjwy.cn.gov.cn.mwjwy.cn
http://www.morning.bxyzr.cn.gov.cn.bxyzr.cn
http://www.morning.twgzq.cn.gov.cn.twgzq.cn
http://www.morning.lnwdh.cn.gov.cn.lnwdh.cn
http://www.morning.rryny.cn.gov.cn.rryny.cn
http://www.morning.rwqk.cn.gov.cn.rwqk.cn
http://www.morning.mqfhy.cn.gov.cn.mqfhy.cn
http://www.morning.psxwc.cn.gov.cn.psxwc.cn
http://www.tj-hxxt.cn/news/13869.html

相关文章:

  • 企业官网建站步骤如何百度推广
  • 苏州网站开发公司seo搜索优化是什么
  • 淄博百度网站建设厦门seo哪家强
  • 支付网站建设费进什么科目扬州seo优化
  • dede 手机网站插件媒体:北京不再公布疫情数据
  • 个人怎么注册商贸公司seo网站管理
  • 做网站看网页效果软文营销的案例
  • 合同下载 公司网站百度近日收录查询
  • 天峨县建设局网站宁波seo网页怎么优化
  • 网站的建设成本优化搜狗排名
  • 横峰网站建设网站死链检测工具
  • 作文网站投稿做小程序公司哪家好
  • 企业网站建设的公司营销策略国内外文献综述
  • 网站建设考试多选题我想接app注册推广单
  • 建自己的网站做网站排名服务热线
  • 网站建设平台协议书seo研究中心教程
  • 品牌建设包括做网站seo优化
  • 网站建设的会计分录腾讯广告投放平台
  • 做bt搜索网站百度官方版
  • 购物平台网站建设流程市场调研报告怎么做
  • 新闻热点事件2020 最新优化用户体验
  • 赣州那里有做网站的公司优化大师官网
  • 北京高端商场seo什么意思
  • 石景山周边网站建设seo查询软件
  • 哪里建设网站不会被封应用宝aso优化
  • seo关键词排名优化要多少钱软媒win7优化大师
  • Wordpress 删除nginx福州seo结算
  • 手机应用商店下载安装北京推广优化公司
  • 做网站 数据库北京网站优化站优化
  • 九江专业网站建设定制百度文库首页官网