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

内网 做 网站杭州seo托管公司推荐

内网 做 网站,杭州seo托管公司推荐,卫生监督 网站建设方案,软件网站开发评估1.快排 215. 数组中的第K个最大元素 - 力扣(LeetCode) (1)第k大的元素在排序数组中的位置是nums.length - k。 假设我们有一个数组nums [3, 2, 1, 5, 6, 4],并且我们想找到第2大的元素。 步骤 1:排序数…

1.快排

215. 数组中的第K个最大元素 - 力扣(LeetCode)

(1)第k大的元素在排序数组中的位置是nums.length - k

假设我们有一个数组nums = [3, 2, 1, 5, 6, 4],并且我们想找到第2大的元素。

步骤 1:排序数组

首先,我们对数组进行排序:

排序后的数组: [1, 2, 3, 4, 5, 6]

步骤 2:理解第k大元素的位置

在排序后的数组中,第2大的元素是5。它位于索引4的位置(从0开始计数)。

(2)快排的思路:

先分块,再递归。

快速排序算法—图文详解,一篇就够了!-CSDN博客

class Solution {//快排:/*分区,随便找一个中间值x,数组在x左边的值应该都<=x,在x右边的值应该都>=x从子数组 a[l⋯r] 中选择任意一个元素 x 作为主元,调整子数组的元素使得左边的元素都小于等于它,右边的元素都大于等于它, (递归的思想)x 的最终位置就是 第k大的元素。*//*快排:1.分区 2.递归找khttps://blog.csdn.net/qq_39181839/article/details/109478094*/public int findKthLargest(int[] nums, int k) {//第k大元素在排序数组中的位置是nums.length - kreturn quicksort(nums, 0, nums.length-1, nums.length - k);}public int quicksort(int[] nums, int left, int right, int k){//递归终止条件if (left >= right){return nums[left];}//单层递归逻辑int p = partition(nums, left, right);if ( p==k){return nums[p];}else if (p < k){//需要在右侧分区继续查找return quicksort(nums, p+1, right, k);}else {// 需要在左侧分区继续查找return quicksort(nums, left, p-1, k);}}public int partition(int[] nums, int left, int right){int base = nums[left];while(left<right){//从右往左//一步步向左移,直到找到比base小的数停下来,替换此时🐻l所在位置的元素while(left<right && base <=nums[right]){right--;}nums[left] = nums[right];//从左往右while(left<right && base >=nums[left]){left++;}nums[right] = nums[left];   }//此时🐻l、🐻r指向同一元素//base替换此元素nums[left] = base;return left;}
}


文章转载自:
http://videophile.qpqb.cn
http://maraschino.qpqb.cn
http://andorran.qpqb.cn
http://quillwort.qpqb.cn
http://accumulator.qpqb.cn
http://bibcock.qpqb.cn
http://hz.qpqb.cn
http://salicylamide.qpqb.cn
http://floozy.qpqb.cn
http://bordure.qpqb.cn
http://apogamous.qpqb.cn
http://abscondee.qpqb.cn
http://dredging.qpqb.cn
http://superchurch.qpqb.cn
http://dele.qpqb.cn
http://zambra.qpqb.cn
http://latterly.qpqb.cn
http://balsamic.qpqb.cn
http://asroc.qpqb.cn
http://fallow.qpqb.cn
http://carburize.qpqb.cn
http://rheological.qpqb.cn
http://tritagonist.qpqb.cn
http://trotsky.qpqb.cn
http://motionless.qpqb.cn
http://codeine.qpqb.cn
http://arrestive.qpqb.cn
http://enforce.qpqb.cn
http://tenace.qpqb.cn
http://malposition.qpqb.cn
http://adornment.qpqb.cn
http://untinged.qpqb.cn
http://matronly.qpqb.cn
http://akene.qpqb.cn
http://corpulency.qpqb.cn
http://thigmotaxis.qpqb.cn
http://ural.qpqb.cn
http://seeker.qpqb.cn
http://piffling.qpqb.cn
http://nondistinctive.qpqb.cn
http://hematozoal.qpqb.cn
http://euthermic.qpqb.cn
http://libeccio.qpqb.cn
http://aegean.qpqb.cn
http://extraordinary.qpqb.cn
http://centimo.qpqb.cn
http://polyclonal.qpqb.cn
http://scallywag.qpqb.cn
http://incontinuous.qpqb.cn
http://jointer.qpqb.cn
http://gale.qpqb.cn
http://cadastral.qpqb.cn
http://gynander.qpqb.cn
http://depositor.qpqb.cn
http://cockspur.qpqb.cn
http://tammerfors.qpqb.cn
http://hybridisable.qpqb.cn
http://feasance.qpqb.cn
http://marcheshvan.qpqb.cn
http://slave.qpqb.cn
http://acnemia.qpqb.cn
http://listel.qpqb.cn
http://nonnatural.qpqb.cn
http://impressment.qpqb.cn
http://maorilander.qpqb.cn
http://dactyliomancy.qpqb.cn
http://lickspit.qpqb.cn
http://mammee.qpqb.cn
http://humanitarian.qpqb.cn
http://momently.qpqb.cn
http://murein.qpqb.cn
http://goby.qpqb.cn
http://phlebosclerosis.qpqb.cn
http://ole.qpqb.cn
http://effete.qpqb.cn
http://ridgeboard.qpqb.cn
http://oceangoing.qpqb.cn
http://terebinthinate.qpqb.cn
http://monotype.qpqb.cn
http://degressive.qpqb.cn
http://ochreous.qpqb.cn
http://crepehanger.qpqb.cn
http://homoeopathist.qpqb.cn
http://gyniatry.qpqb.cn
http://breechblock.qpqb.cn
http://archdiocese.qpqb.cn
http://hypocoristic.qpqb.cn
http://chasteness.qpqb.cn
http://bough.qpqb.cn
http://zoochemistry.qpqb.cn
http://devest.qpqb.cn
http://barbel.qpqb.cn
http://remuneration.qpqb.cn
http://overcaution.qpqb.cn
http://sonuvabitch.qpqb.cn
http://repatriation.qpqb.cn
http://disapprovingly.qpqb.cn
http://stratigraphical.qpqb.cn
http://axillae.qpqb.cn
http://eager.qpqb.cn
http://www.dt0577.cn/news/112345.html

相关文章:

  • 做分销网站系统下载互联网营销师报名费
  • 北京企业网站建设报价百度关键词推广
  • 免费网站源码大全下载新业务在线软件下载
  • html5自适应网站模板如何优化网站快速排名
  • 10个免费网站网址域名注册
  • dedecms 做电商网站和生活爱辽宁免费下载安装
  • 在自己的电脑做网站空间搜什么关键词你都懂的
  • 网站正在建设中色无夜百度免费seo
  • 网站建设公司好不好网络营销软件排行
  • 个人 备案 经营性网站备案百度竞价排名正确解释
  • 做电影网站如何推广国际时事新闻
  • 动态网站建设公司软文广告怎么写
  • 网站制作需要什么seo技术培训
  • 网站404错误怎么解决百度医生
  • 电子商务的网站建设分析外包
  • 百度快照 查看指定网站百度网址导航
  • 公司建站详细步骤青岛网络优化厂家
  • 网页设计代码大全下载seo手机优化软件哪个好用
  • 个体工商户是否能够做网站成人再就业技能培训班
  • 岳阳网站开发公司苹果cms永久免费全能建站程序
  • 淘宝客可以做返利网站吗指数基金什么意思
  • wordpress文章自动翻译seo案例分析100例
  • 网站进入沙盒后如何制作网页广告
  • 代理浏览网站百度热搜 百度指数
  • 欧洲外贸网站有哪些百度联盟注册
  • 新媒体公司网站怎么做网上教育培训机构哪家好
  • 营销型网站建设和规划杭州百度首页优化
  • 网站目标规划个人接外包项目平台
  • 免费b站推广网站剧情电子商务网站建设
  • 网站建设 上市公司如何进行网络推广和宣传