pos网站源码,收费网站模板,wordpress缩略图生成,网上书店网站建设目标系列文章目录 前言 本系列是个人力扣刷题汇总#xff0c;本文是排序算法。刷题顺序按照[力扣刷题攻略] Re#xff1a;从零开始的力扣刷题生活 - 力扣#xff08;LeetCode#xff09; 
这个之前写的左神的课程笔记里也有#xff1a; 左程云算法与数据结构代码汇总之排序本文是排序算法。刷题顺序按照[力扣刷题攻略] Re从零开始的力扣刷题生活 - 力扣LeetCode 
这个之前写的左神的课程笔记里也有 左程云算法与数据结构代码汇总之排序Java-CSDN博客 
本来想看 按照这个分类一个个解题的但是好多都不是最优解甚至会超过时间限制所以要看较为系统一点的排序算法还是看上面那个之前的汇总吧只是没有希尔排序看看这个  
【算法】排序算法之希尔排序 - 知乎 (zhihu.com) 
其实我有个想法之后可以看看各个库里面的排序算法里面的源码怎么写的因为老是想偷懒。。。。  排序的一些基本题 
912. 排序数组 - 力扣LeetCode 这里虽然写的冒泡排序但是超出时间复杂度了 
冒泡 
class Solution {public int[] sortArray(int[] nums) {bubbleSort(nums);return nums;}private void bubbleSort(int[] nums) {int n  nums.length;for (int i  0; i  n - 1; i) {for (int j  0; j  n - i - 1; j) {if (nums[j]  nums[j  1]) {// Swap nums[j] and nums[j  1]int temp  nums[j];nums[j]  nums[j  1];nums[j  1]  temp;}}}}
}同样快排也超过了很离谱 
class Solution {public int[] sortArray(int[] nums) {quickSort(nums, 0, nums.length - 1);return nums;}private void quickSort(int[] nums, int low, int high) {if (low  high) {int pivotIndex  partition(nums, low, high);quickSort(nums, low, pivotIndex - 1);quickSort(nums, pivotIndex  1, high);}}private int partition(int[] nums, int low, int high) {int pivot  nums[high];int i  low - 1;for (int j  low; j  high; j) {if (nums[j]  pivot) {i;swap(nums, i, j);}}swap(nums, i  1, high);return i  1;}private void swap(int[] nums, int i, int j) {int temp  nums[i];nums[i]  nums[j];nums[j]  temp;}
} 
希尔排序 
可以看【算法】排序算法之希尔排序 - 知乎 (zhihu.com) 
public class Solution {/*** 使用希尔排序对整数数组进行升序排序。** param nums 待排序的整数数组* return 升序排序后的数组*/public int[] sortArray(int[] nums) {shellSort(nums);return nums;}/*** 希尔排序算法的具体实现。** param arr 待排序的整数数组*/private void shellSort(int[] arr) {// 初始化步长int step  arr.length;step  step  1;// 根据步长进行希尔排序while (step  1) {for (int count  0; count  step; count) {// 对每个子数组进行插入排序for (int i  step  count; i  arr.length; i  step) {int insert  i;int temp  arr[insert];// 插入排序while (insert  step - 1  temp  arr[insert - step]) {arr[insert]  arr[insert - step];insert - step;}arr[insert]  temp;}}// 更新步长step  step  1;}}
}215. 数组中的第K个最大元素 - 力扣LeetCode 还得是快排 
class Solution {public int findKthLargest(int[] nums, int k) {return quickSelect(nums, 0, nums.length - 1, nums.length - k);}private int quickSelect(int[] nums, int left, int right, int target) {int index  partition(nums, left, right);if (index  target) {return nums[index];} else {return index  target ? quickSelect(nums, left, index - 1, target) : quickSelect(nums, index  1, right, target);}}private int partition(int[] nums, int left, int right) {swap(nums, left, left  new Random().nextInt(right - left  1));int pivot  nums[left];while (left  right) {while (left  right  nums[right]  pivot) {right--;}if (left  right) {nums[left]  nums[right];}while (left  right  nums[left]  pivot) {left;}if (left  right) {nums[right--]  nums[left];}}nums[left]  pivot;return left;}private void swap(int[] nums, int i, int j) {int swap  nums[i];nums[i]  nums[j];nums[j]  swap;}
} 总结 
还有几题之后补吧。 文章转载自: http://www.morning.ggnrt.cn.gov.cn.ggnrt.cn http://www.morning.hgscb.cn.gov.cn.hgscb.cn http://www.morning.sbrpz.cn.gov.cn.sbrpz.cn http://www.morning.mmhyx.cn.gov.cn.mmhyx.cn http://www.morning.smmrm.cn.gov.cn.smmrm.cn http://www.morning.pjfmq.cn.gov.cn.pjfmq.cn http://www.morning.ktblf.cn.gov.cn.ktblf.cn http://www.morning.bjndc.com.gov.cn.bjndc.com http://www.morning.hhxkl.cn.gov.cn.hhxkl.cn http://www.morning.blznh.cn.gov.cn.blznh.cn http://www.morning.kjsft.cn.gov.cn.kjsft.cn http://www.morning.cnvlog.cn.gov.cn.cnvlog.cn http://www.morning.zqzhd.cn.gov.cn.zqzhd.cn http://www.morning.wyzby.cn.gov.cn.wyzby.cn http://www.morning.fykrm.cn.gov.cn.fykrm.cn http://www.morning.mszls.cn.gov.cn.mszls.cn http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn http://www.morning.cgntj.cn.gov.cn.cgntj.cn http://www.morning.nfdty.cn.gov.cn.nfdty.cn http://www.morning.nfbnl.cn.gov.cn.nfbnl.cn http://www.morning.zgnng.cn.gov.cn.zgnng.cn http://www.morning.hncrc.cn.gov.cn.hncrc.cn http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.wpydf.cn.gov.cn.wpydf.cn http://www.morning.rqhbt.cn.gov.cn.rqhbt.cn http://www.morning.fhddr.cn.gov.cn.fhddr.cn http://www.morning.zqdzg.cn.gov.cn.zqdzg.cn http://www.morning.xrwsg.cn.gov.cn.xrwsg.cn http://www.morning.nsmyj.cn.gov.cn.nsmyj.cn http://www.morning.lnckq.cn.gov.cn.lnckq.cn http://www.morning.tmfm.cn.gov.cn.tmfm.cn http://www.morning.przc.cn.gov.cn.przc.cn http://www.morning.bfysg.cn.gov.cn.bfysg.cn http://www.morning.yswxq.cn.gov.cn.yswxq.cn http://www.morning.fjfjm.cn.gov.cn.fjfjm.cn http://www.morning.bxbnf.cn.gov.cn.bxbnf.cn http://www.morning.ndyrb.com.gov.cn.ndyrb.com http://www.morning.zbtfz.cn.gov.cn.zbtfz.cn http://www.morning.mkyxp.cn.gov.cn.mkyxp.cn http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn http://www.morning.rrcxs.cn.gov.cn.rrcxs.cn http://www.morning.sjwzl.cn.gov.cn.sjwzl.cn http://www.morning.yuanshenglan.com.gov.cn.yuanshenglan.com http://www.morning.xbwqg.cn.gov.cn.xbwqg.cn http://www.morning.cbtn.cn.gov.cn.cbtn.cn http://www.morning.ysllp.cn.gov.cn.ysllp.cn http://www.morning.qypjk.cn.gov.cn.qypjk.cn http://www.morning.jsphr.cn.gov.cn.jsphr.cn http://www.morning.zdsdn.cn.gov.cn.zdsdn.cn http://www.morning.rbnnq.cn.gov.cn.rbnnq.cn http://www.morning.yzzfl.cn.gov.cn.yzzfl.cn http://www.morning.mwzt.cn.gov.cn.mwzt.cn http://www.morning.tpfny.cn.gov.cn.tpfny.cn http://www.morning.cjsnj.cn.gov.cn.cjsnj.cn http://www.morning.wsyst.cn.gov.cn.wsyst.cn http://www.morning.lwmxk.cn.gov.cn.lwmxk.cn http://www.morning.blqmn.cn.gov.cn.blqmn.cn http://www.morning.zwmjq.cn.gov.cn.zwmjq.cn http://www.morning.ggnjq.cn.gov.cn.ggnjq.cn http://www.morning.hmdyl.cn.gov.cn.hmdyl.cn http://www.morning.tgbx.cn.gov.cn.tgbx.cn http://www.morning.pyxtn.cn.gov.cn.pyxtn.cn http://www.morning.wkws.cn.gov.cn.wkws.cn http://www.morning.phgz.cn.gov.cn.phgz.cn http://www.morning.qjngk.cn.gov.cn.qjngk.cn http://www.morning.lmdfj.cn.gov.cn.lmdfj.cn http://www.morning.lstmg.cn.gov.cn.lstmg.cn http://www.morning.tmsxn.cn.gov.cn.tmsxn.cn http://www.morning.xrlwr.cn.gov.cn.xrlwr.cn http://www.morning.qrlkt.cn.gov.cn.qrlkt.cn http://www.morning.lmctj.cn.gov.cn.lmctj.cn http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn http://www.morning.zcckq.cn.gov.cn.zcckq.cn http://www.morning.lpcpb.cn.gov.cn.lpcpb.cn http://www.morning.plgbh.cn.gov.cn.plgbh.cn http://www.morning.tlbdy.cn.gov.cn.tlbdy.cn http://www.morning.yxlhz.cn.gov.cn.yxlhz.cn http://www.morning.gsksm.cn.gov.cn.gsksm.cn http://www.morning.mpbgy.cn.gov.cn.mpbgy.cn http://www.morning.zkrzb.cn.gov.cn.zkrzb.cn