文章 212
评论 0
浏览 119899
Binary Search - 378. Kth Smallest Element in a Sorted Matrix

Binary Search - 378. Kth Smallest Element in a Sorted Matrix

Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.

Array - 34. Find First and Last Position of Element in Sorted Array

Array - 34. Find First and Last Position of Element in Sorted Array

Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

Binary Search - 33. Search in Rotated Sorted Array

Binary Search - 33. Search in Rotated Sorted Array

33. Search in Rotated Sorted Array Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists in the array. Your algorithm’s runtime complexity must be in the order of O(log n). Example 1: Input: nums = [4,5,6,7,0,1,2], target = 0 Output: ....

Binary Search - 35. Search Insert Position

Binary Search - 35. Search Insert Position

35. Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5 Output: 2 Example 2: Input: [1,3,5,6], 2 Output: 1 Example 3: Input: [1,3,5,6], 7 Output: 4 Example 4: Input: [1,3,5,6], 0 Output: 0 思路: 题目意思是给定一个有序数组,和一个target,找出target在数组中的下标,或者应该插入的位置。使用binary search来做。 代码: go: func searchInsert(n....

Binary Search - 278. First Bad Version

Binary Search - 278. First Bad Version

278. First Bad Version You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad. You are given an API bool isBadVersion(vers....

Nothing just happens, it's all part of a plan.