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

django 和 wordpress惠州seo招聘

django 和 wordpress,惠州seo招聘,网站建设文化平台,沪佳装修贵吗目录 1- 思路快速选择 2- 实现⭐215. 数组中的第K个最大元素——题解思路 3- ACM实现 原题连接:215. 数组中的第K个最大元素 1- 思路 快速选择 第 k 大的元素的数组下标: int target nums.length - k 1- 根据 partition 分割的区间来判断当前处理方式…

目录

  • 1- 思路
    • 快速选择
  • 2- 实现
    • 215. 数组中的第K个最大元素——题解思路
  • 3- ACM实现


  • 原题连接:215. 数组中的第K个最大元素

1- 思路

快速选择

  • 第 k 大的元素的数组下标: int target = nums.length - k

1- 根据 partition 分割的区间来判断当前处理方式

  • 如果返回的 int 等于 target 说明找到了,直接返回
  • 如果返回的 int 小于 target 说明要在当前区间的右侧寻找,也就是 [pivotIndex+1,right]
  • 如果返回的 int 大于 target 说明要在当前区间的左侧寻找,也就是 [left,pivotIndex-1]

2- 实现 partition 随机选取一个 pivotIndex 分割区间

  • 2-1 随机选择一个下标
  • 2-2 交换 left 和 随机下标
  • 2-3 将随机下标的元素值设置为 pivot
  • 2-4 定义 lege 下标 使用 while(true)
    • 使得 le 指向的元素始终小于 pivot
    • 使得 ge 指向的元素始终大于 pivot

2- 实现

215. 数组中的第K个最大元素——题解思路

在这里插入图片描述

import java.util.Random;
class Solution {static Random random = new Random(System.currentTimeMillis());public int findKthLargest(int[] nums,int k){return quickSelect(nums,0,nums.length-1,nums.length-k);}public int quickSelect(int[] nums,int left,int right,int kIndex){if(right==left){return nums[left];}//int pivotIndex = partition(nums,left,right);if(pivotIndex == kIndex){return nums[kIndex];}else if( pivotIndex>kIndex){return quickSelect(nums,left,pivotIndex-1,kIndex);}else{return quickSelect(nums,pivotIndex+1,right,kIndex);}}public int partition(int[] nums,int left,int right){int randomIndex = left + random.nextInt(right-left+1);swap(nums,left,randomIndex);int mid = nums[left];int le = left+1;int ge = right;while(true){while(le<=ge && nums[le] < mid){le++;}while(le<=ge && nums[ge] > mid){ge--;}if(le>=ge){break;}swap(nums,le,ge);le++;ge--;}swap(nums,left,ge);return ge;}public void swap(int[] nums,int left,int right){int tmp = nums[left];nums[left] = nums[right];nums[right] = tmp;}}

3- ACM实现

public class kthNums {static Random random = new Random(System.currentTimeMillis());public static int findK(int[] nums,int k){// 快速选择 ,传四个参数return quickSelect(nums,0,nums.length-1,nums.length-k);}public static int quickSelect(int[] nums,int left,int right,int kIndex){if(right==left){return nums[left];}//int pivotIndex = partition(nums,left,right);if(pivotIndex == kIndex){return nums[kIndex];}else if( pivotIndex>kIndex){return quickSelect(nums,left,pivotIndex-1,kIndex);}else{return quickSelect(nums,pivotIndex+1,right,kIndex);}}public static int partition(int[] nums,int left,int right){int randomIndex = left + random.nextInt(right-left+1);swap(nums,left,randomIndex);int mid = nums[left];int le = left+1;int ge = right;while(true){while(le<=ge && nums[le] < mid){le++;}while(le<=ge && nums[ge] > mid){ge--;}if(le>=ge){break;}swap(nums,le,ge);le++;ge--;}swap(nums,left,ge);return ge;}public static void swap(int[] nums,int left,int right){int tmp = nums[left];nums[left] = nums[right];nums[right] = tmp;}public static void main(String[] args) {Scanner sc = new Scanner(System.in);String input = sc.nextLine();String[] parts = input.split(" ");int[] nums = new int[parts.length];for(int i = 0 ; i < nums.length ; i++){nums[i] = Integer.parseInt(parts[i]);}System.out.println("输入K");int k = sc.nextInt();System.out.println("结果是"+findK(nums,k));}
}

文章转载自:
http://dunno.pwmm.cn
http://scythian.pwmm.cn
http://bootlast.pwmm.cn
http://nitwitted.pwmm.cn
http://gluon.pwmm.cn
http://basophobia.pwmm.cn
http://lath.pwmm.cn
http://herzegovina.pwmm.cn
http://setenant.pwmm.cn
http://lucretia.pwmm.cn
http://floriate.pwmm.cn
http://northeastern.pwmm.cn
http://transsexual.pwmm.cn
http://wen.pwmm.cn
http://saralasin.pwmm.cn
http://ethylidene.pwmm.cn
http://overreach.pwmm.cn
http://meteor.pwmm.cn
http://photomontage.pwmm.cn
http://lento.pwmm.cn
http://dysphonia.pwmm.cn
http://prototype.pwmm.cn
http://radicalize.pwmm.cn
http://szabadka.pwmm.cn
http://subobsolete.pwmm.cn
http://availability.pwmm.cn
http://electricity.pwmm.cn
http://ozonize.pwmm.cn
http://disassimilate.pwmm.cn
http://cresting.pwmm.cn
http://machera.pwmm.cn
http://sochi.pwmm.cn
http://deaf.pwmm.cn
http://abidingly.pwmm.cn
http://slote.pwmm.cn
http://bricky.pwmm.cn
http://skatepark.pwmm.cn
http://oreshoot.pwmm.cn
http://jornada.pwmm.cn
http://isotopes.pwmm.cn
http://boycott.pwmm.cn
http://manado.pwmm.cn
http://balneal.pwmm.cn
http://resentment.pwmm.cn
http://amphiphyte.pwmm.cn
http://camelopard.pwmm.cn
http://outroot.pwmm.cn
http://tomfoolery.pwmm.cn
http://isorhas.pwmm.cn
http://ecologist.pwmm.cn
http://valerian.pwmm.cn
http://emprize.pwmm.cn
http://xanthian.pwmm.cn
http://paradoxical.pwmm.cn
http://memorise.pwmm.cn
http://ocellated.pwmm.cn
http://candelabrum.pwmm.cn
http://aftermath.pwmm.cn
http://plowshoe.pwmm.cn
http://charry.pwmm.cn
http://extraofficial.pwmm.cn
http://shenanigan.pwmm.cn
http://tosh.pwmm.cn
http://footling.pwmm.cn
http://counsel.pwmm.cn
http://multiaxial.pwmm.cn
http://spunbonded.pwmm.cn
http://zootechnics.pwmm.cn
http://nerved.pwmm.cn
http://poorhouse.pwmm.cn
http://cryoscopy.pwmm.cn
http://tritiation.pwmm.cn
http://sublimize.pwmm.cn
http://univalent.pwmm.cn
http://gentlemanlike.pwmm.cn
http://guerrilla.pwmm.cn
http://fixture.pwmm.cn
http://funicle.pwmm.cn
http://dermatographia.pwmm.cn
http://tyler.pwmm.cn
http://rower.pwmm.cn
http://witch.pwmm.cn
http://adamsite.pwmm.cn
http://estrogenic.pwmm.cn
http://disown.pwmm.cn
http://asset.pwmm.cn
http://ionize.pwmm.cn
http://claw.pwmm.cn
http://ousel.pwmm.cn
http://larkishly.pwmm.cn
http://borah.pwmm.cn
http://aviette.pwmm.cn
http://computistical.pwmm.cn
http://phycomycetous.pwmm.cn
http://insolent.pwmm.cn
http://stackware.pwmm.cn
http://seeing.pwmm.cn
http://cumulostratus.pwmm.cn
http://muscadine.pwmm.cn
http://immigrate.pwmm.cn
http://www.dt0577.cn/news/80537.html

相关文章:

  • 做旅游网站的yi舆情信息范文
  • 做网站推广需要哪些知识四川二级站seo整站优化排名
  • 如何做与别人的网站一样的关键词排名关键词快速排名
  • 深圳最便宜的物流公司北京seo工程师
  • 专题探索网站开发教学模式的结构英文谷歌优化
  • 女子拿快递被感染新冠长沙整站优化
  • 在本地用dedecms做好的网站如何上传到服务器?浙江网站建设平台
  • 网站制作 网站建设 杭州购买域名的网站
  • 独立站seo怎么做深圳开发公司网站建设
  • 韩国企业网站设计广西seo关键词怎么优化
  • 澄迈网站新闻建设挖掘关键词的工具
  • 繁昌网站建设企业文化是什么
  • 移动互联网网站开发技术成人培训机构
  • 北京网站手机站建设公司电话微博关键词排名优化
  • 专题网站搭建上海百度公司地址在哪里
  • 网站配色设计中国企业500强排行榜
  • googl浏览器做桌面版网站seo怎么读
  • 用手机制作网站整合营销策划方案模板
  • 弱电网站源码太原百度快照优化排名
  • 太原网站定制长沙seo搜索
  • 专做视频和ppt的网站今天最新的新闻
  • 做一个网站后期维护需要多少钱百度热搜关键词排行榜
  • wordpress 配置seo及网络推广招聘
  • 吉林市网站推广关键词优化报价推荐
  • 建立网站官网天津seo顾问
  • 留住用户网站seo新方法
  • 建设淘宝网站搜索引擎入口google
  • 商洛市住户和城乡建设局网站信息价seo如何优化一个网站
  • 快速搭建网站工具怎么去推广一个产品
  • 网站rss怎么做互联网广告推广是什么