08 2021 档案
摘要:1. 某个数是否存在于二维数组中 1 public boolean search(int[][] m, int target) { 2 if (m.length == 0 || m[0].length == 0) { 3 return false; 4 } 5 int l = 0; 6 int r
阅读全文
摘要:1. 二叉树的最大子bst树 使用二叉树套路 bst树的特点左边的最大值小于根节点的值 右边的最小值 大于根节点的值 注意判断null值 因为结束条件返回的null 1 public TreeNode node(TreeNode head) { 2 BSTInfo process = process
阅读全文
摘要:1. 给一个数组标识不同距离的点 给一个长度为5的绳子看最多能覆盖多少个点 思路1: 使用二分查找到大于等于当前点-5的最左的点 坐标相减得到结果 logn 思路2: 时间窗口的模式,l在第一个点 r右移 满足条件长度加一 l走完数组结束 左右两个边界都不需要回退 o(n) 1 public int
阅读全文
摘要:普通二分查找 public static int search(int[] arr, int target) { int l = 0; int r = arr.length; while (l < r) { int mid = l + ((r - l) >> 1); if (arr[mid] < t
阅读全文