![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
mkl34367803
假如编程易懂得,那么程序员就不会热情地写出注释,也不会有得到编程的快乐。
展开
-
力扣leetcode第146题LRU缓存机制
使用HashMap+双链表的方式实现。 使用HashMap可以在O(1)的时间查询到缓存key,使用双链表是因为插入的时候要在头部插入,删除最少使用的key需要尾部删除。 import java.util.HashMap; import java.util.Map; class LRUCache { /** * ["LRUCache","put","put","put","put","get","get","get","get","put","get","get","g..原创 2021-03-23 14:38:12 · 191 阅读 · 2 评论 -
快速排序java代码(从大到小排序)
代码如下: public class QuickSort { public static void main(String[] args) { int[] nums=new int[]{23,383,9,84,13,55}; new QuickSort().quickSort(nums,0,nums.length-1); Arrays.stream(nums).forEach(System.out::println); }原创 2021-03-21 12:49:47 · 1510 阅读 · 0 评论 -
快速选择排序(java代码),用于解决寻找最小的k个元素或者最大的k个元素。
代码如下,基于快速排序,但是只根据要找寻的前k个目标,对部分区域进行排序。 public class QuickSelectSort { public static void main(String[] args) { int[] nums=new int[]{13,81,92,43,65,31,57,26,75,0}; new QuickSelectSort().quickSelectSort(nums,0,nums.length-1,1); //k为1代表前原创 2021-03-21 12:11:33 · 221 阅读 · 2 评论