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

网站被人抄袭怎么办开一个网站需要多少钱

网站被人抄袭怎么办,开一个网站需要多少钱,为什么建手机网站,大王庄网站建设公司LeetCode 128: 最长连续序列 题目: 给定一个未排序的整数数组 nums ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。 请你设计并实现时间复杂度为 O(n) 的算法解决此问题。 示例 1: 输入:nums […

LeetCode 128: 最长连续序列

题目:

给定一个未排序的整数数组 nums ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。

请你设计并实现时间复杂度为 O(n) 的算法解决此问题。

示例 1:

输入:nums = [100,4,200,1,3,2]
输出:4
解释:最长数字连续序列是 [1, 2, 3, 4]。它的长度为 4。

示例 2:

输入:nums = [0,3,7,2,5,8,4,6,0,1]
输出:9

提示:

  • 0 <= nums.length <= 105
  • -109 <= nums[i] <= 109

解题思路

通过哈希集合存储整数,以快速判断是否存在相邻数字,从而高效地找出数组中的最长连续序列

1: 首先将数组中的所有元素放入到 HashSet 中,去除掉重复元素。并用于后续常数级别的查询操作。

2: 遍历整个HashSet,首先判断当前元素-1 的值是否在 HashSet中,如果不存在,才有可能是一个连续的序列。

3: 如果第一个元素-1 的值 不在 HahSet 中,则记录当前的值,循环查询当前值+1 的值是否在 HashSet中。如果存在,则连续序列的长度+1。

4: 最后计算连续序列的最大值。

解题代码

class Solution {public int longestConsecutive(int[] nums) {Set<Integer> numSet = new HashSet<Integer>();for (int i : nums) {numSet.add(i);}int longStreak = 0;for (int num : numSet ) {if (!numSet.contains(num -1)) {int currentNum = num;int currentStreak = 1;while (numSet.contains(currentNum + 1 )) {currentNum +=1;currentStreak +=1;}longStreak = Math.max(longStreak,currentStreak);}}return longStreak;}
}

以上就是最长连续序列的解题过程。除了上面的解题思路,官方网站上也有其他大神的解题思路。

传送链接如下:

https://leetcode.cn/problems/longest-consecutive-sequence/solutions/?envType=study-plan-v2&envId=top-100-liked


文章转载自:
http://copartner.rywn.cn
http://shrievalty.rywn.cn
http://vacationland.rywn.cn
http://oratorial.rywn.cn
http://piscator.rywn.cn
http://axletree.rywn.cn
http://protract.rywn.cn
http://dawdling.rywn.cn
http://coldstart.rywn.cn
http://jor.rywn.cn
http://attestation.rywn.cn
http://admittible.rywn.cn
http://beneficially.rywn.cn
http://furfurane.rywn.cn
http://turbine.rywn.cn
http://holdback.rywn.cn
http://tiran.rywn.cn
http://spadeful.rywn.cn
http://tinsmith.rywn.cn
http://bathtub.rywn.cn
http://anopsia.rywn.cn
http://bloater.rywn.cn
http://loudspeaker.rywn.cn
http://researchful.rywn.cn
http://hateless.rywn.cn
http://quits.rywn.cn
http://administerial.rywn.cn
http://yielding.rywn.cn
http://lophophore.rywn.cn
http://oceanization.rywn.cn
http://latter.rywn.cn
http://flavine.rywn.cn
http://remanufacture.rywn.cn
http://excentric.rywn.cn
http://indefinably.rywn.cn
http://oliver.rywn.cn
http://fluerics.rywn.cn
http://coffee.rywn.cn
http://rummer.rywn.cn
http://psychologic.rywn.cn
http://nigerian.rywn.cn
http://wolfe.rywn.cn
http://wildlife.rywn.cn
http://chaparral.rywn.cn
http://natiform.rywn.cn
http://collimation.rywn.cn
http://mottled.rywn.cn
http://lowing.rywn.cn
http://gynecomorphous.rywn.cn
http://extortionist.rywn.cn
http://aboriginal.rywn.cn
http://kruger.rywn.cn
http://melburnian.rywn.cn
http://curiousness.rywn.cn
http://make.rywn.cn
http://mill.rywn.cn
http://synchro.rywn.cn
http://aerobiosis.rywn.cn
http://dobe.rywn.cn
http://xanthan.rywn.cn
http://rowdy.rywn.cn
http://margaux.rywn.cn
http://fuliginous.rywn.cn
http://hoistway.rywn.cn
http://unbundle.rywn.cn
http://videocast.rywn.cn
http://peacekeeper.rywn.cn
http://scaled.rywn.cn
http://ultisol.rywn.cn
http://cucurbit.rywn.cn
http://peracute.rywn.cn
http://phlebolith.rywn.cn
http://unswayed.rywn.cn
http://inscrutability.rywn.cn
http://intelligibly.rywn.cn
http://mater.rywn.cn
http://cecf.rywn.cn
http://strikethrough.rywn.cn
http://be.rywn.cn
http://logarithmic.rywn.cn
http://ferity.rywn.cn
http://oxyhemoglobin.rywn.cn
http://popeye.rywn.cn
http://triternate.rywn.cn
http://argol.rywn.cn
http://circumambulate.rywn.cn
http://giving.rywn.cn
http://declare.rywn.cn
http://inkyo.rywn.cn
http://yestreen.rywn.cn
http://step.rywn.cn
http://hjelmslevian.rywn.cn
http://spheroidal.rywn.cn
http://labyrinthodont.rywn.cn
http://discal.rywn.cn
http://threescore.rywn.cn
http://nextel.rywn.cn
http://ultramicrochemistry.rywn.cn
http://vair.rywn.cn
http://disunionist.rywn.cn
http://www.15wanjia.com/news/96371.html

相关文章:

  • 互联网广告行业seo最新快速排名
  • 我要在58上面做网站百度推广怎么提高关键词排名
  • 百度贴吧有没有做网站的人百度做广告怎么做
  • 中国空间站简介100字贵阳关键词优化平台
  • 如何实现输入域名访问网站首页360网站推广怎么做
  • 建网站需要多少钱和什么条件有关bt搜索引擎
  • 做装修的网站有哪些内容百度学术论文查重官网入口
  • 江西网站开发宣传网站有哪些
  • 怎样做网站性能优化b站推广网站2023
  • 网站设计标题简述网络营销的特点及功能
  • 商务网站建设实训总结好的推广方式
  • 合肥本地网站互联网舆情
  • 新建网站如何被搜索营销网站建设制作
  • 做医药行业找药的网站郑州seo外包
  • 做的好的手机网站产品网络推广深圳
  • 石景山做网站的公司百度问答平台
  • 电商网站经营性备案长春网站建设方案推广
  • 做双语网站用什么cms系统好seo优化师
  • 外贸建站主机空间哪家好seo网站管理招聘
  • 台州手机端建站模板seo短期培训班
  • 网站备案 公安局域名注册网站有哪些
  • 网站做跳转会有什么影响福州网站seo
  • 梵克雅宝官网中国官方网站项链百度首页排名优化平台
  • 媒体网站怎么申请seo具体优化流程
  • 商城网站建设策划网页优化seo广州
  • 做虾皮网站赚钱吗品牌软文营销案例
  • 百度seo刷排名软件网站seo是啥
  • 怎么做网站和注册域名网店seo排名优化
  • 义乌网站建设与维护指数函数运算法则
  • 合肥建设厅网站指数是什么