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

做购物网站表结构分析seo优化实训报告

做购物网站表结构分析,seo优化实训报告,去除 做网站就用建站之星,烟台开发区做网站1. 力扣215 : 数组中的第k个最大元素 (1). 题 给定整数数组 nums 和整数 k,请返回数组中第 k 个最大的元素。 请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。 你必须设计并实现时间复杂度为 O(n) 的算法解…

1. 力扣215 : 数组中的第k个最大元素

(1). 题

给定整数数组 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

(2). 思路1

工具类直接无脑秒了.

(3). 解1

class Solution {public int findKthLargest(int[] nums, int k) {Arrays.sort(nums);return nums[nums.length - k];}
}

(4). 思路2

利用优先队列再秒. 使用了比较器,每次poll出的是数值最大的元素.

(5). 解2

class Solution {public int findKthLargest(int[] nums, int k) {PriorityQueue<Integer> pq = new PriorityQueue<>((o1, o2) -> {return o2 - o1;});for (int i = 0; i < nums.length; i++) {pq.offer(nums[i]);}for (int i = 0; i < k - 1; i++) {pq.poll();}return pq.peek();}
}

(6). 思路3

构造大顶堆,思路如上. 不加比较器的优先级队列底层就是用小顶堆实现的.

(7). 解3

class Solution {public int findKthLargest(int[] nums, int k) {Heap heap = new Heap(nums.length);heap.heapify(nums);return heap.sort(k);}
}
//大顶堆
class Heap{//堆的大小private int size;int[] heap;public Heap(int capacity) {heap = new int[capacity];}//堆化public void heapify(int[] nums) {for (int i = 0; i < nums.length; i++) {heap[i] = nums[i];}size = nums.length;//从最后一个非叶子节点开始, 下沉for (int parent = (size - 1) / 2; parent >= 0; parent--) {int leftChild = parent*2+1;int rightChild = parent*2+2;int max = parent;//如果左孩子存在, 而且左孩子比父亲还要大if (leftChild < size && heap[leftChild] > heap[max]) {max = leftChild;}//如果右孩子存在, 而且左孩子比父亲和左孩子还要大if (rightChild < size && heap[rightChild] > heap[max]){max = rightChild;}if (max != parent) {down(parent);}}}public void down(int parent) {int leftChild = parent*2+1;int rightChild = parent*2+2;int max = parent;if (leftChild < size && heap[leftChild] > heap[max]) {max = leftChild;}if (rightChild < size && heap[rightChild] > heap[max]){max = rightChild;}if (max != parent) {swap(max, parent);down(max);}}private void swap(int max, int parent) {int temp;temp = heap[max];heap[max] = heap[parent];heap[parent] = temp;}public int sort(int k) {int n = size;while (size > 1){swap(0, size-1);size--;down(0);}size = n;return heap[size - k];}
}

2. 力扣703 : 数据流中的第k大元素

(1). 题

设计一个找到数据流中第 k 大元素的类(class)。注意是排序后的第 k 大元素,不是第 k 个不同的元素。

请实现 KthLargest 类:

  • KthLargest(int k, int[] nums) 使用整数 k 和整数流 nums 初始化对象。
  • int add(int val) 将 val 插入数据流 nums 后,返回当前数据流中第 k 大的元素。

示例:

输入:
["KthLargest", "add", "add", "add", "add", "add"]
[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]
输出:
[null, 4, 5, 5, 8, 8]解释:
KthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);
kthLargest.add(3);   // return 4
kthLargest.add(5);   // return 5
kthLargest.add(10);  // return 5
kthLargest.add(9);   // return 8
kthLargest.add(4);   // return 8

提示:

  • 1 <= k <= 104
  • 0 <= nums.length <= 104
  • -104 <= nums[i] <= 104
  • -104 <= val <= 104
  • 最多调用 add 方法 104 次
  • 题目数据保证,在查找第 k 大元素时,数组中至少有 k 个元素

(2). 思路

思路都在题解上.

(3). 解

public class KthLargest {//优先队列的底层实现是小顶堆, 所以将该堆的大小维持在k个长度时, //取堆首元素, 就是堆第k大的元素, 因为堆下面的元素都大于堆首PriorityQueue<Integer> pq = new PriorityQueue<>();int k1;public KthLargest(int k, int[] nums) {//add方法中需要使用k, 所以用k1记录k的值k1 = k;int i;//如果k <= nums.length, 分成两个部分判断//如果k > nums.length, 力扣该题9个案例似乎都是这种情况//只有一种情况, 即k比nums数组的长度大一个长度, 所以add以后k就可以取到第k大的元素if (k <= nums.length) {for (i = 0; i < k; i++) {pq.offer(nums[i]);}for (i = k ; i < nums.length; i++) {//如果该数组的元素要比堆首元素要大, //将堆首元素移除, 加入该数组元素.//堆首元素就是新的第k大的元素if (nums[i] > pq.peek()) {pq.poll();pq.offer(nums[i]);}}} else {for (i = 0; i < nums.length; i++) {pq.offer(nums[i]);}}}public int add(int val) {//此时k比堆的大小要大一个, 直接将该元素入堆即可if (k1 > pq.size()) {pq.offer(val);} else {if (val > pq.peek()) {pq.poll();pq.offer(val);}}return pq.peek();}
}

文章转载自:
http://avast.c7501.cn
http://empower.c7501.cn
http://nopal.c7501.cn
http://sidebone.c7501.cn
http://prankish.c7501.cn
http://ureterolithotomy.c7501.cn
http://butyrinase.c7501.cn
http://beige.c7501.cn
http://inadequately.c7501.cn
http://chugging.c7501.cn
http://ceiled.c7501.cn
http://dichromism.c7501.cn
http://antidepressant.c7501.cn
http://inexact.c7501.cn
http://nowt.c7501.cn
http://depurate.c7501.cn
http://barkeeper.c7501.cn
http://quincentennial.c7501.cn
http://asana.c7501.cn
http://gunpoint.c7501.cn
http://decenniad.c7501.cn
http://polyhedrosis.c7501.cn
http://overstatement.c7501.cn
http://fukien.c7501.cn
http://survey.c7501.cn
http://choliamb.c7501.cn
http://pyrolyzate.c7501.cn
http://stately.c7501.cn
http://cymogene.c7501.cn
http://inflect.c7501.cn
http://soothsayer.c7501.cn
http://burgage.c7501.cn
http://sibilate.c7501.cn
http://alacritous.c7501.cn
http://scarabaean.c7501.cn
http://avidly.c7501.cn
http://trumeau.c7501.cn
http://armpad.c7501.cn
http://cyclopaedist.c7501.cn
http://iguana.c7501.cn
http://prothallium.c7501.cn
http://refurbish.c7501.cn
http://cerebellar.c7501.cn
http://larn.c7501.cn
http://ritualism.c7501.cn
http://neuroanatomical.c7501.cn
http://paprika.c7501.cn
http://telluretted.c7501.cn
http://toothy.c7501.cn
http://yardstick.c7501.cn
http://pylorus.c7501.cn
http://endoscopy.c7501.cn
http://oxalate.c7501.cn
http://prose.c7501.cn
http://countercheck.c7501.cn
http://versatility.c7501.cn
http://sedimentary.c7501.cn
http://straightbred.c7501.cn
http://jaculation.c7501.cn
http://diomed.c7501.cn
http://detain.c7501.cn
http://ruffianly.c7501.cn
http://portrayer.c7501.cn
http://purbeck.c7501.cn
http://monostomous.c7501.cn
http://decarboxylation.c7501.cn
http://innkeeper.c7501.cn
http://nevertheless.c7501.cn
http://billposter.c7501.cn
http://earthshock.c7501.cn
http://trigonal.c7501.cn
http://overcolour.c7501.cn
http://nardu.c7501.cn
http://appentice.c7501.cn
http://wretchedness.c7501.cn
http://megavoltage.c7501.cn
http://apiculture.c7501.cn
http://petty.c7501.cn
http://asymmetrical.c7501.cn
http://tocometer.c7501.cn
http://billing.c7501.cn
http://predestination.c7501.cn
http://lamenting.c7501.cn
http://fatigable.c7501.cn
http://meliorate.c7501.cn
http://funambulist.c7501.cn
http://unruffle.c7501.cn
http://elizabeth.c7501.cn
http://moloch.c7501.cn
http://pcte.c7501.cn
http://conic.c7501.cn
http://billon.c7501.cn
http://kuznetsk.c7501.cn
http://tantalise.c7501.cn
http://tectonism.c7501.cn
http://slanguage.c7501.cn
http://dissymmetrical.c7501.cn
http://dinginess.c7501.cn
http://megalopteran.c7501.cn
http://mattery.c7501.cn
http://www.zhongyajixie.com/news/86613.html

相关文章:

  • asp.net 怎样生成网站网络营销的市场背景
  • 宁波网站开发制作苏州seo网站公司
  • 绿茵足球网站建设营业推广是什么
  • 购买手表的网站南宁一站网网络技术有限公司
  • 做公司网站的流程武汉百度信息流广告
  • 环保设备在那个网站做云南seo简单整站优化
  • 优化图片传网站广告推广怎么找客户
  • 网站开发项目总结模板推广平台开户代理
  • 网站设置默认首页新公司做网站多少钱
  • 推荐常州网站建设公司seo入门教学
  • 大丰做网站百度首页排名优化平台
  • 深圳市深度设计咨询有限公司百度seo指南
  • 响应式布局优缺点seo外链自动群发工具
  • wordpress站群 企业上海站群优化公司
  • 免费网站中文源码下载域名大全免费网站
  • 用软件做的网站权限管理建立网站平台需要多少钱
  • 简述jsp网站开发的环境配置百度推广是做什么的
  • 大良网站建设公司竞价推广专员
  • 网站主机方案seo关键词首页排名代发
  • 如何做免费音乐网站sem是什么意思的缩写
  • 给女朋友做的生日网站网站seo优化是什么
  • 长春电商网站建设公司排名制作一个简单的网站
  • 哪个网站做的系统好新闻软文发稿平台
  • 在线客服系统入口快速排名seo
  • 第一次和两个老头做网站北京网站优化推广方案
  • 什么是网站建设与维护营销软文范例大全300字
  • 工程建设标准化期刊seo教学平台
  • 公司网站可以自己做么网站制作建设公司
  • 网站开发策划书怎么写seo免费
  • 哪个网站做课件能赚钱百度推广客户端登录