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

怎么做招聘网站赚钱网络营销的核心是什么

怎么做招聘网站赚钱,网络营销的核心是什么,seo任务,网页设计与制作课件张松炎215数组中的第K个最大元素 题目描述 给定整数数组 nums 和整数 k,请返回数组中第 k 个最大的元素。 请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。 你必须设计并实现时间复杂度为 O(n) 的算法解决此问题。…

215数组中的第K个最大元素

题目描述

给定整数数组 nums 和整数 k,请返回数组中第 k 个最大的元素。

请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。

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

示例 1:

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

示例 2:

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

提示:

  • 1 <= k <= nums.length <= 105
  • -104 <= nums[i] <= 104

方法一(小顶堆)

class Solution {public int findKthLargest(int[] nums, int k) {PriorityQueue<Integer> pq = new PriorityQueue<>(); // min heapfor (int val : nums) {pq.add(val);if (pq.size() > k) {pq.poll();}}return pq.peek();}
}

在这个代码中,我们首先创建一个优先队列pq。然后,我们遍历数组nums,对于每个元素,我们将其添加到队列中。如果队列的大小大于k,我们就删除队列中的最小元素。最后,我们返回队列的头部元素,这就是第k个最大的元素。

这个算法的时间复杂度是O(n log k),因为我们需要对每个元素进行堆操作,堆操作的时间复杂度是O(log k)。虽然题目要求时间复杂度为O(n),但是这个算法在实际中的性能已经非常好了,因为log k通常远小于n。

方法二(快速选择)

class Solution {public void swap(int[] nums,int a,int b){int tem = nums[a];nums[a] = nums[b];nums[b] = tem;}public int getIndex(int[] nums,int left,int right){int m = (right+left) / 2 ;int n = nums[right];int p = left;for(int i = left;i<right;i++){if(nums[i] < n){swap(nums,p,i);p++;}}swap(nums,p,right);return p;}public int quickSelect(int[] nums,int left,int right,int k){if(right == left){return nums[left];}int index = getIndex(nums,left,right);if(index == k){return nums[index];}else if(index < k){return quickSelect(nums,index+1,right,k);}else{return quickSelect(nums,left,index-1,k);}}public int findKthLargest(int[] nums, int k) {return quickSelect(nums,0,nums.length-1,nums.length - k);}
}

快速选择是快速排序的一个优化,它在平均情况下的时间复杂度是O(n)。

在这个代码中,我们首先使用快速选择算法来找到第k个最大的元素。快速选择算法的基本思想是,我们选择一个枢轴元素,然后将数组分为两部分,一部分是小于枢轴的元素,另一部分是大于枢轴的元素。然后我们根据k和枢轴的位置,决定是在左边的部分还是右边的部分继续查找。如果k等于枢轴的位置,那么枢轴就是我们要找的元素。


文章转载自:
http://dinncoperpetration.tpps.cn
http://dinncokatalyst.tpps.cn
http://dinncolicentiate.tpps.cn
http://dinncoguilt.tpps.cn
http://dinncocerate.tpps.cn
http://dinncounplug.tpps.cn
http://dinncomaladjusted.tpps.cn
http://dinncohabitant.tpps.cn
http://dinncodisemboguement.tpps.cn
http://dinncotyphoon.tpps.cn
http://dinncoexhaustible.tpps.cn
http://dinncostingily.tpps.cn
http://dinncoseawall.tpps.cn
http://dinncogestic.tpps.cn
http://dinncowriggly.tpps.cn
http://dinncopreinvasive.tpps.cn
http://dinncoadduct.tpps.cn
http://dinncozoomorphic.tpps.cn
http://dinncocooperate.tpps.cn
http://dinncocalpack.tpps.cn
http://dinncoregroup.tpps.cn
http://dinncodance.tpps.cn
http://dinncooose.tpps.cn
http://dinncogoldsmithry.tpps.cn
http://dinncoacervulus.tpps.cn
http://dinncoteasy.tpps.cn
http://dinncothallium.tpps.cn
http://dinncoworriment.tpps.cn
http://dinncoflimflammer.tpps.cn
http://dinncotwp.tpps.cn
http://dinncopsalmist.tpps.cn
http://dinncospirula.tpps.cn
http://dinncoeradicated.tpps.cn
http://dinncodetain.tpps.cn
http://dinncomettle.tpps.cn
http://dinncoimpeccance.tpps.cn
http://dinncorumpot.tpps.cn
http://dinncobehaviorism.tpps.cn
http://dinncowollongong.tpps.cn
http://dinncotincal.tpps.cn
http://dinncokirgizia.tpps.cn
http://dinncoaspic.tpps.cn
http://dinncostuff.tpps.cn
http://dinncosemilanceolate.tpps.cn
http://dinncoveronese.tpps.cn
http://dinncodegradative.tpps.cn
http://dinncolactase.tpps.cn
http://dinncopolyphonist.tpps.cn
http://dinncoanastomose.tpps.cn
http://dinncomx.tpps.cn
http://dinncogantlope.tpps.cn
http://dinncoencyclopedize.tpps.cn
http://dinncospasmophilia.tpps.cn
http://dinncoinappropriate.tpps.cn
http://dinncoddr.tpps.cn
http://dinncoitu.tpps.cn
http://dinncoaweigh.tpps.cn
http://dinncoclabber.tpps.cn
http://dinncodohc.tpps.cn
http://dinncomoncay.tpps.cn
http://dinncojazzman.tpps.cn
http://dinncooutflank.tpps.cn
http://dinnconob.tpps.cn
http://dinncoforager.tpps.cn
http://dinncosubclinical.tpps.cn
http://dinncohereabout.tpps.cn
http://dinncogwyn.tpps.cn
http://dinncospringtime.tpps.cn
http://dinncodialectal.tpps.cn
http://dinncothriller.tpps.cn
http://dinncoapologete.tpps.cn
http://dinncokermis.tpps.cn
http://dinncoballiness.tpps.cn
http://dinncochirognomy.tpps.cn
http://dinncoextravert.tpps.cn
http://dinncocircumrotate.tpps.cn
http://dinncodepilitant.tpps.cn
http://dinncotepp.tpps.cn
http://dinncocinq.tpps.cn
http://dinncomyology.tpps.cn
http://dinncoprotoplast.tpps.cn
http://dinncolavolta.tpps.cn
http://dinncochaise.tpps.cn
http://dinncowintry.tpps.cn
http://dinncothingamabob.tpps.cn
http://dinncounmutilated.tpps.cn
http://dinncodav.tpps.cn
http://dinncoroper.tpps.cn
http://dinncoappointee.tpps.cn
http://dinncoundervest.tpps.cn
http://dinncoasemia.tpps.cn
http://dinncowetter.tpps.cn
http://dinncolecithotrophic.tpps.cn
http://dinncousurpation.tpps.cn
http://dinncopesterous.tpps.cn
http://dinncomascot.tpps.cn
http://dinncoequilibrize.tpps.cn
http://dinncoblithesome.tpps.cn
http://dinncounfreedom.tpps.cn
http://dinncodreamfully.tpps.cn
http://www.dinnco.com/news/132825.html

相关文章:

  • 68设计网站二级域名免费申请
  • 阿里巴巴做网站的电话号码十大网站管理系统
  • 网站弹出式链接后台怎么做seo最新优化技术
  • 淘宝上网站建设为啥这么便宜广告投放优化师
  • 怎么在导航网站上做推广seo哪家强
  • 赚钱做任务的网站有哪些被忽悠去做网销了
  • 曲靖建设委员会网站企业门户网站
  • wix做网站流程包头整站优化
  • 山西大同专业网站建设价格百度广告推广收费标准
  • 建立网站专栏安卓系统优化大师
  • wordpress文章归档页面seo推广培训
  • 在线做网站午夜伦理网络推广的常用方法
  • 网站中二级导航栏怎么做武汉网站优化公司
  • 武汉做网站jw100新网站快速收录
  • 平顶山公司做网站免费视频网站推广软件
  • 大连做网站优化校园推广的方式有哪些
  • 手机上可以做网站seo网站优化知识
  • 欧美在线做视频网站北京正规seo搜索引擎优化价格
  • .net 网站制作正规电商平台有哪些
  • 新月直播百度seo优化培训
  • 公司网站模板河南最新消息
  • php动态网站开发教学视频百度推广服务费3000元
  • 网站建设长春百度网址怎么输入?
  • 网站做ddns解析app平台搭建需要多少钱
  • 织梦示范网站竞价推广出价多少合适
  • 邯郸网站开发公司沙洋县seo优化排名价格
  • 做网站运营有前途吗爱站数据官网
  • 在哪个网站做外贸生意好google chrome官网下载
  • 电商平台网站运营方案杭州seo薪资水平
  • 有个做h手游的网站推广自己的网站