![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode-binary search
文章平均质量分 73
shanshanhi
这个作者很懒,什么都没留下…
展开
-
349.Intersection of Two AND 350. Intersection of Two Arrays II Arrays leetcode binary search
Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should r原创 2017-01-02 15:47:10 · 273 阅读 · 0 评论 -
367. Valid Perfect Square
367. Valid Perfect SquareGiven a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.原创 2017-01-06 11:38:59 · 284 阅读 · 0 评论 -
35. Search Insert Position
35. Search Insert PositionGiven 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原创 2017-01-11 15:58:58 · 266 阅读 · 0 评论 -
34. Search for a Range
34. Search for a RangeGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the原创 2017-01-11 17:23:31 · 308 阅读 · 0 评论 -
74. Search a 2D Matrix AND 240. Search a 2D Matrix II leetcode binary search
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of原创 2017-01-04 14:20:39 · 468 阅读 · 0 评论 -
(待研究)50. Pow(x, n)
50. Pow(x, n)Implement pow(x, n).leetcode 上的top解法nest myPowdouble myPow(double x, int n) { if(n0) return 1/x * myPow(1/x, -(n+1)); if(n==0) return 1; if(n==2) return转载 2017-01-07 19:00:22 · 278 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
4. Median of Two Sorted ArraysThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be转载 2017-01-11 19:53:02 · 632 阅读 · 0 评论 -
(待进一步研究吃透)209. Minimum Size Subarray Sum
209. Minimum Size Subarray SumGiven an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0转载 2017-01-07 18:46:17 · 289 阅读 · 0 评论 -
287. Find the Duplicate Number
可采用hash、暴力、排序、映射、二分等多种方法。Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only...原创 2017-01-04 10:59:02 · 294 阅读 · 0 评论 -
222. Count Complete Tree Nodes
222. Count Complete Tree NodesGiven a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except po转载 2017-01-07 19:35:03 · 263 阅读 · 0 评论 -
162. Find Peak Element
162. Find Peak ElementA peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array m原创 2017-01-07 17:34:22 · 316 阅读 · 0 评论 -
441. Arranging Coins
441. Arranging CoinsYou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircas原创 2017-01-07 12:24:55 · 278 阅读 · 0 评论 -
392. Is Subsequence leetcode binary search
Is Subsequence Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 5原创 2017-01-03 12:05:57 · 399 阅读 · 0 评论 -
378. Kth Smallest Element in a Sorted Matrix leetcode binary_search 378
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, n转载 2017-01-03 18:17:24 · 316 阅读 · 0 评论 -
230. Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the B转载 2017-01-03 18:18:51 · 365 阅读 · 0 评论 -
454. 4Sum II leetcode binary search
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same length...原创 2017-01-04 09:22:53 · 479 阅读 · 0 评论 -
153. Find Minimum in Rotated Sorted Array leetcode binary search
Suppose a sorted array 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).Find the minimum element.You may assume no duplicate exists in原创 2017-01-04 13:46:42 · 278 阅读 · 0 评论 -
154. Find Minimum in Rotated Sorted Array II leetcode binary search
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some piv原创 2017-01-04 13:48:37 · 327 阅读 · 0 评论 -
69. Sqrt(x)
69. Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.此题同367题不同之处在于,此题徐哟求出sqrt(x)的值,而367题则不需要,367只用简单的判断是不是有个数的平方等于整数x方法一、二分查找法int mySqrt(int x) { if(原创 2017-01-06 14:34:12 · 427 阅读 · 0 评论 -
33. Search in Rotated Sorted Array AND 81. Search in Rotated Sorted Array II
33. Search in Rotated Sorted ArraySuppose 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原创 2017-01-06 17:40:11 · 284 阅读 · 0 评论 -
(待整理)300. Longest Increasing Subsequence
300. Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest inc原创 2017-01-07 12:01:11 · 300 阅读 · 0 评论