
排序
九幽孤翎
蜉蝣只有认清自己的渺小,才能有化茧成蝶的一天
展开
-
Leetcode_324_摆动序列2_三向切分
进阿里实习后都没什么时间写题了QAQ坑蛮多的这题,进阶做法也很难。最朴素的想法就是互插,小的数一组,大的数一组,然后插在一起。但这种做法在小的组最大的数和大的组最小的数相同时会出现问题,所以必须得反插,就是把两组数全部倒过来互插,使得小的组最大的数和大的组最小的数分开。...原创 2022-06-29 09:59:23 · 154 阅读 · 0 评论 -
Leetcode_215_数组中的第K个最大元素_快速排序
class Solution { Random random = new Random(); public int findKthLargest(int[] nums, int k) { return quickSort(nums, 0, nums.length - 1, nums.length - k); } int quickSort(int[] nums, int start, int end, int target) { // 随机原创 2021-08-26 15:59:51 · 121 阅读 · 0 评论 -
Leetcode_4_寻找两个正序数组的中位数_合并
12/13复杂度(n+m)class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int n1=nums1.length; int n2=nums2.length; if(n1+n2==0){ return 0; } int st1=0; int st2=0;原创 2020-12-13 10:32:06 · 326 阅读 · 0 评论 -
Leetcode_164_最大间距_基数排序_桶排序
11/26暴力做法就运行速度而言完爆桶排和基数排序原因在于桶排的复杂度虽然是O(n),但是其最坏情况下是31倍的n,而快排是nlogn,也就是n>31^31的时候,才能体现桶排的优势基数排序也是一个道理虽然复杂度低了,但最前面的系数也不能忽略class Solution { public int maximumGap(int[] nums) { Arrays.sort(nums); int maxx=0; for(int i=1;原创 2020-11-26 19:49:51 · 342 阅读 · 0 评论 -
Leetcode_147_对链表进行插入排序_数据结构+插入排序
class Solution { public ListNode insertionSortList(ListNode head) { //防止调用head.next报错 if (head == null) { return head; } //相当于c++里的头指针 ListNode dummyHead = new ListNode(0); dummyHead.next = he原创 2020-11-21 22:44:37 · 328 阅读 · 0 评论 -
Leetcode_1030_距离顺序排序矩阵单元格_排序_bfs
11/17初步思路排个序就完事了class Solution { public int[][] allCellsDistOrder(int R, int C, int r0, int c0) { int[][] ans = new int[R*C][2]; int num=0; for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) {原创 2020-11-17 20:06:13 · 376 阅读 · 0 评论 -
Leetcode_406_根据身高重建队列_贪心+排序
11/16杂记:想直接用JAVA写然后发现Arraylist不会用特意去看了一下JAVA编程思想中List的相关章节中文版p454 原版p781知识点汇总:二维数组的行数:a.length二维数组的列数:a[0].length排序Arrays.sort(people, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) {原创 2020-11-16 11:24:46 · 342 阅读 · 0 评论