![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二分
涛涛酱
北邮研究僧在读
展开
-
【LeetCode 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.Y原创 2020-06-02 17:06:05 · 112 阅读 · 0 评论 -
【LeetCode 300】 Longest Increasing Subsequence Medium
题目描述Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. Note:There may be mo原创 2020-05-31 00:58:54 · 113 阅读 · 0 评论 -
【LeetCode 315】 Count of Smaller Numbers After Self
题目描述You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].Example:Input: [5,2,6,1]Output: [2,1,1,0] Explanation:To th原创 2020-05-20 23:06:37 · 152 阅读 · 0 评论 -
【LeetCode 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.Your algorithm’s runtime complexity must be in the order of O(log n).If the target is not found in the array, return [-1, -1].E原创 2020-05-20 22:46:27 · 118 阅读 · 0 评论 -
【LeetCode 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], 5Output: 2Example 2:原创 2020-05-20 22:23:44 · 92 阅读 · 0 评论 -
【LeetCode 975】 Odd Even Jump
题目描述You are given an integer array A. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, …) jumps in the series are called odd numbered jumps, and the (2nd, 4th, 6th, …) ...原创 2020-03-05 16:01:58 · 146 阅读 · 0 评论 -
【LeetCode 410】 Split Array Largest Sum
题目描述Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these ...原创 2020-02-27 19:57:48 · 123 阅读 · 0 评论 -
【LeetCode 719】 Find K-th Smallest Pair Distance
题目描述Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B.Example 1:Input:nums = [1,3,1...原创 2020-02-21 16:33:00 · 187 阅读 · 0 评论 -
二分查找总结
https://blog.csdn.net/Hide_in_Code/article/details/76549317原创 2020-02-17 21:51:09 · 143 阅读 · 0 评论 -
【LeetCode 69】Sqrt(x)
题目描述Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and o...原创 2020-02-14 15:06:16 · 84 阅读 · 0 评论 -
【LeetCode 162】 Find Peak Element
题目描述A peak element is an element that is greater than its neighbors.Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.The array may contain multiple pea...原创 2020-02-10 15:45:09 · 81 阅读 · 0 评论 -
【LeetCode 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 foun...原创 2020-01-17 11:02:12 · 93 阅读 · 0 评论 -
【LeetCode Contest 142.】1093 - 1096
…周赛一道题都没出,先是晚上了半个点。然后1093读错题,mode疯狂猜想是取模,原来是众数。然后1094以为是树状数组或者并查集,原来只是一个模拟。后两道没看,比赛就过去了。过去了。去了。了。卒。1093. Statistics from a Large Sample对0 to 256的数进行采样,每个数字可能采样 0 to 10910^{9}109次,求出采样数据的最小值,最大值,平均数...原创 2019-06-24 11:14:39 · 270 阅读 · 0 评论 -
【LeetCode 4.】Median of Two Sorted Arrays
题目大意:给两个有序数组,求出合并以后的中位数。要求时间复杂度:O(m+n)思路:思路1:分别标记两个数组的移动位置,移动两个数组当前小的那个数字所在位置,直到移动到中位数所在位置。时间复杂度 O(n)。思路2:二分。问题转化为求所有数字的第k小数,每次比较a[k/2-1]和b[k/2-1],如果两个数字相等,则找到第k小数。否则可以排除掉k/2个数字。时间复杂度 O(log(m+n))...原创 2019-06-26 14:30:21 · 96 阅读 · 0 评论 -
【剑指 offer】数字在排序数组中出现的次数
题目描述:统计一个数字在数组中出现的次数。思路:二分查找数组中第一次出现数字k的位置。代码:class Solution {public: int GetNumberOfK(vector<int> data, int k) { if (data.empty()) return 0; int len = data.size(); ...原创 2019-04-07 18:24:48 · 61 阅读 · 0 评论 -
【LeetCode 315】Count of Smaller Numbers After Self
题目描述:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].exampl...原创 2019-03-19 09:49:33 · 89 阅读 · 0 评论 -
【LeetCode 300】 Longest Increasing Subsequence
题目描述:Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7...原创 2019-03-22 11:22:34 · 69 阅读 · 0 评论 -
【leetcode 378】 Kth Smallest Element in a Sorted Matrix(C++)
题目描述: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.Note that it is the kth smallest element in the sorted order, ...原创 2019-02-26 11:34:59 · 216 阅读 · 0 评论