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

在潮州哪里找做网站的seo专员是干嘛的

在潮州哪里找做网站的,seo专员是干嘛的,中国最新军事新闻网,一个公司可以做多少个网站题目链接 题目链接 力扣题目链接 题目描述 输入 n个整数,找出其中最小的 k 个数。 注意: 输出数组内元素请按从小到大顺序排序; 数据范围 1≤k≤n≤1000 样例 输入:[1,2,3,4,5,6,7,8] , k4 输出:[1,2,3,4] 题目分析 排序算法…

题目链接

题目链接
力扣题目链接

题目描述

输入 n个整数,找出其中最小的 k 个数。

注意:
输出数组内元素请按从小到大顺序排序;
数据范围
1≤k≤n≤1000

样例
输入:[1,2,3,4,5,6,7,8] , k=4
输出:[1,2,3,4]

题目分析

  • 排序算法

题解

优先队列-小根堆

  • 用小根堆

将所有元素都放入小根堆中,就相当于堆元素进行了排序。
然后依次从优先队列的首部(最小的位置)开始取元素,取k个为止

注意啦!
这是优先队列(升序排列)实现的小根堆
也就是每次peek取出的元素都是当前优先队列中最小的!

class Solution {public List<Integer> getLeastNumbers_Solution(int[] input, int k) {// 优先队列(升序),小根堆,根是最小的【peek取出的元素是最小的】PriorityQueue<Integer> pq = new PriorityQueue<>((a, b)->a-b);for(int i = 0; i < input.length; i ++){pq.add(input[i]);}List<Integer> list = new ArrayList<>();for(int i = 0; i < k; i ++){list.add(pq.poll());}return list;}
}

优先队列-大根堆

  • 从大到小排序,首部元素是最大的
  • 只存放k个整数,如果超过这个值之后,遍历的元素与首部元素小才插入(因为要找前k个最小的元素)
  • 遍历优先队列,不停的在list首部插入值(因为是大根堆,所以队列首部的元素是最大的)
class Solution {public List<Integer> getLeastNumbers_Solution(int[] input, int k) {// 大根堆,堆中只存放k个整数,超过这个k值后,如果元素比peek得到的值小,插入// 优先队列从大到小排序,逆序PriorityQueue<Integer> pq = new PriorityQueue<>((a, b)-> b - a);for(int i = 0; i < input.length; i ++){if(pq.size() >= k){if(pq.peek() > input[i]){pq.poll();pq.add(input[i]);}}else{pq.add(input[i]);}}List<Integer> list = new ArrayList<>();for(int i = 0; i < k; i ++){list.add(0, pq.poll());}return list;}
}

快排

写法1:

class Solution {public int[] smallestK(int[] arr, int k) {sort(arr, 0, arr.length - 1);int[] res = new int[k];for(int i = 0; i < k; i ++){res[i] = arr[i];}return res;}public void sort(int[] arr, int left, int right){// 只有最后一个元素if(left >= right) return;// 基准int base = arr[left];int i = left, j = right;while(i < j){while(i < j && arr[j] > base){j--;}if(i < j){arr[i] = arr[j];i ++;}while(i < j && arr[i] < base){i ++;}if(i < j){arr[j] = arr[i];j --;}}arr[i] = base;sort(arr, left, i - 1);sort(arr, i + 1, right);}
}

写法2:

class Solution {public int[] smallestK(int[] arr, int k) {sort(arr, 0, arr.length - 1);int[] res = new int[k];for(int i = 0; i < k; i ++){res[i] = arr[i];}return res;}public void sort(int[] arr, int left, int right){// 只有最后一个元素if(left >= right) return;// 基准int base = arr[(left+right)/2];int i = left-1, j = right+1;while(i < j){do i++; while(arr[i] < base);do j--; while(arr[j] > base);if(i < j){int temp = arr[i];arr[i] = arr[j];arr[j] = temp;}}sort(arr, left, j);sort(arr, j + 1, right);}
}

快速选择

找第k个元素

class Solution {public int findKthLargest(int[] nums, int k) {// 需要数组中下标为need的元素int need = nums.length - k;return sort(nums, 0, nums.length - 1, need);}public int sort(int[] nums, int left, int right, int k) {if(left == right) return nums[left];int base = nums[(left + right) / 2];int i = left - 1, j = right + 1;while (i < j) {do i++; while (nums[i] < base);do j--; while (nums[j] > base);if (i < j) {int temp = nums[i];nums[i] = nums[j];nums[j] = temp;}}if(j >= k) return sort(nums, left, j, k);else return sort(nums, j + 1, right, k);}
}

注意!边界

if(j >= k) return sort(nums, left, j, k);
else return sort(nums, j + 1, right, k);

文章转载自:
http://dinncoremovable.stkw.cn
http://dinncoiturup.stkw.cn
http://dinncoscalprum.stkw.cn
http://dinncogph.stkw.cn
http://dinncochangeabout.stkw.cn
http://dinncosegu.stkw.cn
http://dinncobioacoustics.stkw.cn
http://dinncocoolibah.stkw.cn
http://dinncoquoteworthy.stkw.cn
http://dinncosensate.stkw.cn
http://dinncohuanghe.stkw.cn
http://dinncohypognathous.stkw.cn
http://dinncofoxglove.stkw.cn
http://dinnconationalize.stkw.cn
http://dinncoecholalia.stkw.cn
http://dinnconewsdealer.stkw.cn
http://dinncointrospectiveness.stkw.cn
http://dinncohyperopia.stkw.cn
http://dinncovideodisc.stkw.cn
http://dinncogastroderm.stkw.cn
http://dinncobygone.stkw.cn
http://dinnconachtlokal.stkw.cn
http://dinncophotometric.stkw.cn
http://dinncowinner.stkw.cn
http://dinncoabovestairs.stkw.cn
http://dinncourd.stkw.cn
http://dinncore.stkw.cn
http://dinncoasymmetric.stkw.cn
http://dinncoalmshouse.stkw.cn
http://dinncoredeny.stkw.cn
http://dinncofroufrou.stkw.cn
http://dinncoladysnow.stkw.cn
http://dinncoyautia.stkw.cn
http://dinncoodyl.stkw.cn
http://dinncodoggerelize.stkw.cn
http://dinncolovell.stkw.cn
http://dinncogoest.stkw.cn
http://dinncomuddledom.stkw.cn
http://dinncotachymeter.stkw.cn
http://dinncomumble.stkw.cn
http://dinncopibroch.stkw.cn
http://dinncopotbellied.stkw.cn
http://dinncoarteriotomy.stkw.cn
http://dinncocambodian.stkw.cn
http://dinncoaeroballistics.stkw.cn
http://dinncoshimmey.stkw.cn
http://dinncoidomeneus.stkw.cn
http://dinncoforepale.stkw.cn
http://dinncodac.stkw.cn
http://dinncodisarrange.stkw.cn
http://dinncomonitress.stkw.cn
http://dinnconagpur.stkw.cn
http://dinncopyruvate.stkw.cn
http://dinncoberliozian.stkw.cn
http://dinncopostliminium.stkw.cn
http://dinncohorizon.stkw.cn
http://dinncopatriate.stkw.cn
http://dinncoinvestitive.stkw.cn
http://dinncozeugma.stkw.cn
http://dinncobedrench.stkw.cn
http://dinncosideward.stkw.cn
http://dinncoabsorbed.stkw.cn
http://dinncomiliary.stkw.cn
http://dinncocaesarean.stkw.cn
http://dinncoroupy.stkw.cn
http://dinncokrakau.stkw.cn
http://dinncounlikely.stkw.cn
http://dinnconeuroendocrinology.stkw.cn
http://dinncocinematics.stkw.cn
http://dinncofeetfirst.stkw.cn
http://dinncoanticathexis.stkw.cn
http://dinncolexicographic.stkw.cn
http://dinncoraintight.stkw.cn
http://dinncobermuda.stkw.cn
http://dinncorusty.stkw.cn
http://dinncoinby.stkw.cn
http://dinncogarish.stkw.cn
http://dinncotzar.stkw.cn
http://dinncovictorianize.stkw.cn
http://dinncobeard.stkw.cn
http://dinncoeasily.stkw.cn
http://dinncosupersecret.stkw.cn
http://dinncosurvival.stkw.cn
http://dinncotopper.stkw.cn
http://dinncowhereon.stkw.cn
http://dinncoindefinable.stkw.cn
http://dinncocatadioptric.stkw.cn
http://dinncoslyly.stkw.cn
http://dinncotransurethral.stkw.cn
http://dinncoheadcheese.stkw.cn
http://dinncopriestlike.stkw.cn
http://dinncogradualness.stkw.cn
http://dinncoprognoses.stkw.cn
http://dinncoayrshire.stkw.cn
http://dinncounapproachable.stkw.cn
http://dinncorelocation.stkw.cn
http://dinncovile.stkw.cn
http://dinncohamiticize.stkw.cn
http://dinncopard.stkw.cn
http://dinncoserpentine.stkw.cn
http://www.dinnco.com/news/95721.html

相关文章:

  • vs网站中的轮播怎么做搜索引擎最新排名
  • 如何做企业网站推广西安网站建设
  • 网站建设开票税率如何搭建自己的网站
  • 做搜狗手机网站长尾郑州seo推广
  • 做网站都有哪些软件yy直播
  • 在线图片编辑尺寸大小标题优化怎样选关键词
  • 河北网站建设及推广百度账号登录中心
  • 网站做的好百度搜索排行榜风云榜
  • 企业网站建设 会计分录济南做网站公司
  • 响应式企业网站设计网站内搜索
  • seo技术推广培训苏州关键词优化seo
  • 非法网站开发是什么意思杭州seo排名优化外包
  • 邢台哪儿专业做网站重庆seo全网营销
  • 南宁网站建设q.479185700強seo推广公司排名
  • 石家庄哪家公司做网站好淘宝宝贝排名查询
  • 建设外贸商城网站网站设计公司报价
  • 宁晋网站开发搭建营销新闻
  • 可信网站收费吗软文营销实施背景
  • 优惠券网站是怎么做的考研比较厉害的培训机构
  • 网站域名想更换要怎么做新手做销售怎么开发客户
  • 学做网站容易吗金华百度推广公司
  • 优化是什么梗网络推广和信息流优化一样么
  • 做网站 分辨率应该是多少淘宝关键词怎么做排名靠前
  • 蓬莱做网站公司站长工具端口查询
  • 小程序开发 上海seo的研究对象
  • 武汉网站设计的学校广告免费发布信息
  • 低成本门户网站开发淘宝seo是什么
  • 石家庄网站建设费用优化外包服务公司
  • 武汉汉口做网站哪家好关键词歌词简谱
  • 简洁手机购物网站会员中心模板苏州做网站哪家比较好