随笔分类 -  BinarySearch

二分查找
[Leetcode 701]二叉搜索树BST中插入元素
摘要:题目 BST二叉搜索树中插入元素 二叉搜索树:左边<root<右边 https://leetcode.com/problems/insert-into-a-binary-search-tree/ You are given the root node of a binary search tree 阅读全文
posted @ 2021-12-04 08:10 alau 阅读(73) 评论(0) 推荐(0)
[Leetcode 162]寻找峰值 Find Peak Element**
摘要:【题目】 寻找峰值返回坐标,比左右都大,时间复杂度必须是 O(log n) A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a pe 阅读全文
posted @ 2021-08-19 14:58 alau 阅读(64) 评论(0) 推荐(0)
[Leetcode 152]旋转数组中找到最小值Find Minimum in Rotated Sorted Array
摘要:【题目】 说了一堆就是在旋转后的顺序数组中找最小值,时间复杂度必须是 O(log n) Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the 阅读全文
posted @ 2021-08-19 14:17 alau 阅读(53) 评论(0) 推荐(0)
[Leetcode 33/81]有序旋转数组找值Search in Rotated Sorted Array
摘要:leetcode33 【题目】 顺序排列的数组,每个点值不同。以某个点进行旋转(其实就是前后两段交换位置),对旋转后数组搜索有无target,没有-1,有返回位置 (变式81不同点在于会出现重复数字) There is an integer array nums sorted in ascendin 阅读全文
posted @ 2021-08-19 09:05 alau 阅读(47) 评论(0) 推荐(0)
[Leetcode 74/240]二维数组中找目标值Search a 2D Matrix
摘要:leetcode74 【题目】 二维矩阵里找目标值target Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: I 阅读全文
posted @ 2021-08-18 21:16 alau 阅读(83) 评论(0) 推荐(0)
[Leetcode 278]第一个出错的版本 First Bad Version
摘要:【题目】 一个版本出错,后续版本皆错,找到第一个出错的版本 You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of yo 阅读全文
posted @ 2021-08-18 20:55 alau 阅读(39) 评论(0) 推荐(0)
[Leetcode 349]两个数组的相同元素Intersection of Two Arrays
摘要:【题目】 找到两个数组的相同元素并输出。 Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and yo 阅读全文
posted @ 2021-08-18 16:45 alau 阅读(111) 评论(0) 推荐(0)
[Leetcode 35]在顺序数组中找到插入位置Search Insert Position 二分
摘要:【题目】 非负的有序数组中,如果有与target相同的,输出该数位置,如果没有,输出应该将target插到哪个位置 Given a sorted array of distinct integers and a target value, return the index if the target 阅读全文
posted @ 2021-08-18 16:22 alau 阅读(61) 评论(0) 推荐(0)
[Leetcode 69]开根号Sqrt(x) 二分查找易错点
摘要:【题目】 对非负数求平方根,不能调用系统自带库 Given a non-negative integer x, compute and return the square root of x. Since the return type is an integer, the decimal digi 阅读全文
posted @ 2021-08-18 15:44 alau 阅读(173) 评论(0) 推荐(0)
[Leetcode easy]存些水题34、20、700
摘要:leetcode 34 最早出现和最后出现 class Solution { public int[] searchRange(int[] nums, int target) { int []ans={-1,-1} ; for(int i=0;i<nums.length;i++){ if(nums[ 阅读全文
posted @ 2018-11-20 13:40 alau 阅读(114) 评论(0) 推荐(0)