摘要: 对于有序数组,才能使用二分查找法,需要先排序,常应用于需要多次查找的情况 选定一个标定点,将数组分为左右两个区间,时间复杂度为O(logn) 递归写法 public class Algorithm { public static void main(String[] args) { Integer[ 阅读全文
posted @ 2021-10-24 20:25 振袖秋枫问红叶 阅读(67) 评论(0) 推荐(0)
摘要: public class Algorithm { public static void main(String[] args) { Integer[] arr = {1,2,3,4,5,6,7}; System.out.println(new BinarySearch().search(arr, 4 阅读全文
posted @ 2021-10-24 16:05 振袖秋枫问红叶 阅读(24) 评论(0) 推荐(0)
摘要: 快速排序法 import java.util.Arrays; public class Algorithm { public static void main(String[] args) { int[] arr = {1,3,5,7,2,4,6,8}; System.out.println(Arr 阅读全文
posted @ 2021-10-24 15:05 振袖秋枫问红叶 阅读(29) 评论(0) 推荐(0)
摘要: import java.util.Arrays; public class Algorithm { public static void main(String[] args) { int[] arr = {1,3,5,7,2,4,6,8}; System.out.println(Arrays.to 阅读全文
posted @ 2021-10-24 14:58 振袖秋枫问红叶 阅读(38) 评论(0) 推荐(0)
摘要: 双指针法(双路快速排序法) class Solution { public int findKthLargest(int[] nums, int k) { /** * 第k大的元素等同于第length - k小的元素 */ int target = nums.length - k; return s 阅读全文
posted @ 2021-10-24 14:43 振袖秋枫问红叶 阅读(56) 评论(0) 推荐(0)