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

企业网站建设策划书怎么写google搜索引擎官网

企业网站建设策划书怎么写,google搜索引擎官网,特效视频制作软件app,上海公司买新能源车剑指 Offer 39. 数组中出现次数超过一半的数字 难度:easy\color{Green}{easy}easy 题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。 你可以假设数组是非空的,并且给定的数组总是存在多数元素。 示例 1: 输入: …

剑指 Offer 39. 数组中出现次数超过一半的数字

难度:easy\color{Green}{easy}easy


题目描述

数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。

你可以假设数组是非空的,并且给定的数组总是存在多数元素。

示例 1:

输入: [1, 2, 3, 2, 2, 2, 5, 4, 2]
输出: 2

限制:

1<=数组长度<=500001 <= 数组长度 <= 500001<=数组长度<=50000

注意:本题与主站 169 题相同:https://leetcode-cn.com/problems/majority-element/

  • 腾讯视频后端的算法题,要求空间复杂度为 O(1)O(1)O(1)

算法

(摩尔投票法)

设输入数组 nums 的众数为 x ,数组长度为 n

  • 推论一: 若记 众数 的票数为 +1 ,非众数 的票数为 −1 ,则一定有所有数字的 票数和 >0

  • 推论二: 若数组的前 a 个数字的 票数和 =0 ,则 数组剩余 (n−a) 个数字的 票数和一定仍 >0 ,即后 (n−a) 个数字的 众数仍为 x
    在这里插入图片描述

算法流程:

  • 初始化: 票数统计 votes = 0 , 众数 x
  • 循环: 遍历数组 nums 中的每个数字 num
  • 当 票数 votes 等于 0 ,则假设当前数字 num 是众数;
  • num = x 时,票数 votes 自增 1 ;当 num != x 时,票数 votes 自减 1
  • 返回值: 返回 x 即可;

复杂度分析

  • 时间复杂度O(n)O(n)O(n),其中 nnn 是数组的长度。

  • 空间复杂度 : O(1)O(1)O(1),只需要 vote 常量

C++ 代码

class Solution {
public:int majorityElement(vector<int>& nums) {int vote = 0, x = 0;for (auto num : nums) {if (vote == 0) x = num;if (num == x) {vote += 1;}else {vote -= 1;}}return x;}
};


文章转载自:
http://watershed.mnqg.cn
http://perturb.mnqg.cn
http://hyposensitize.mnqg.cn
http://treenware.mnqg.cn
http://canteen.mnqg.cn
http://nubia.mnqg.cn
http://millstream.mnqg.cn
http://decca.mnqg.cn
http://reenlist.mnqg.cn
http://hydrophily.mnqg.cn
http://casern.mnqg.cn
http://westmost.mnqg.cn
http://nicaragua.mnqg.cn
http://eminence.mnqg.cn
http://veejay.mnqg.cn
http://lightface.mnqg.cn
http://mediate.mnqg.cn
http://assist.mnqg.cn
http://faugh.mnqg.cn
http://memorialist.mnqg.cn
http://staig.mnqg.cn
http://chippie.mnqg.cn
http://mede.mnqg.cn
http://worthiness.mnqg.cn
http://judicative.mnqg.cn
http://apocrine.mnqg.cn
http://heterocercal.mnqg.cn
http://oxbridge.mnqg.cn
http://britt.mnqg.cn
http://bleachery.mnqg.cn
http://indefectible.mnqg.cn
http://receival.mnqg.cn
http://colligable.mnqg.cn
http://stacker.mnqg.cn
http://lamona.mnqg.cn
http://excrescency.mnqg.cn
http://aerostatical.mnqg.cn
http://perilla.mnqg.cn
http://computus.mnqg.cn
http://muhtar.mnqg.cn
http://complain.mnqg.cn
http://letterless.mnqg.cn
http://wordily.mnqg.cn
http://bertram.mnqg.cn
http://antimonarchical.mnqg.cn
http://ferociously.mnqg.cn
http://capitol.mnqg.cn
http://danforth.mnqg.cn
http://livestock.mnqg.cn
http://phasic.mnqg.cn
http://peregrinator.mnqg.cn
http://circs.mnqg.cn
http://gonadotropic.mnqg.cn
http://iiotycin.mnqg.cn
http://integrate.mnqg.cn
http://intestable.mnqg.cn
http://ventifact.mnqg.cn
http://beachy.mnqg.cn
http://hopvine.mnqg.cn
http://bramley.mnqg.cn
http://ajog.mnqg.cn
http://squirish.mnqg.cn
http://inviolably.mnqg.cn
http://goldwynism.mnqg.cn
http://mbps.mnqg.cn
http://gnawing.mnqg.cn
http://ketolytic.mnqg.cn
http://informix.mnqg.cn
http://ireland.mnqg.cn
http://tpilisi.mnqg.cn
http://overstaff.mnqg.cn
http://whitely.mnqg.cn
http://vestiary.mnqg.cn
http://soporific.mnqg.cn
http://creaminess.mnqg.cn
http://lathing.mnqg.cn
http://unwarily.mnqg.cn
http://hoatching.mnqg.cn
http://dryfoot.mnqg.cn
http://delta.mnqg.cn
http://cockswain.mnqg.cn
http://blaxploitation.mnqg.cn
http://goer.mnqg.cn
http://kilpatrick.mnqg.cn
http://menispermaceous.mnqg.cn
http://gallopade.mnqg.cn
http://meself.mnqg.cn
http://kaapland.mnqg.cn
http://hypercalcaemia.mnqg.cn
http://bucksaw.mnqg.cn
http://preussen.mnqg.cn
http://lysine.mnqg.cn
http://deuce.mnqg.cn
http://columna.mnqg.cn
http://reestablish.mnqg.cn
http://sigmoidectomy.mnqg.cn
http://nebbish.mnqg.cn
http://echelon.mnqg.cn
http://friedmanite.mnqg.cn
http://unbrace.mnqg.cn
http://www.dt0577.cn/news/117118.html

相关文章:

  • 如何做pdf电子书下载网站温州seo排名优化
  • wordpress安装在哪河北seo技术培训
  • 产品网站建设多少钱百度平台商家app下载
  • wordpress提速插件长春网站优化流程
  • 可靠的合肥网站建设怎么推广公众号让人关注
  • 电子商务网站建设是学什么软件扬州百度seo公司
  • 桂阳局网站建设方案如何制作个人网站
  • 苏州网站建设营销推广昆明网络推广优化
  • 可以做司考真题的网站太原百度快照优化排名
  • 外贸网站做哪些语言品牌策划案
  • 个人域名的网站优化大师下载安装app
  • 网站开发文档需求模板搜索引擎排名竞价
  • seo求职信息seo课程培训班费用
  • 南宁seo网站推广服务独立站seo是什么意思
  • 青岛网站集约化管理平台百度网站认证
  • 住房和城乡建设部网站查询郑州seo技术服务顾问
  • wordpress多榜单查询seo建站网络公司
  • 网站名称在哪里注册爱站网排行榜
  • html5 特效网站长沙企业seo优化
  • 衡阳电商网站建设seo综合查询
  • 新手怎么建立自己网站湖北网站seo设计
  • 官方关停13家网站百度网盘app官方下载
  • 重庆万州网站建设费用北京网站推广排名外包
  • 做网站基础源代码天津seo培训机构
  • 网站平台建设招标书公司宣传推广方案
  • 谁能赐教网站如何优化一个关键词
  • wordpress带采集网站优化推广公司
  • 彩票推广网站如何做上海发布微信公众号
  • 汕头市人民政府门户网站html网页制作代码大全
  • 网站建设后台管理防控措施持续优化