binary search
文章平均质量分 68
yuanhisn
这个作者很懒,什么都没留下…
展开
-
Count the number of occurrences in a sorted array
Given a sorted array arr[] and a number x, write a function that counts the occurrences of x in arr[]. Expected time complexity is O(Logn) Examples: Input: arr[] = {1, 1, 2, 2, 2, 2, 3,}, x = ...原创 2015-05-01 05:56:36 · 75 阅读 · 0 评论 -
LeetCode 162 - Find Peak Element
A 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 may contain multiple peaks, in th...原创 2015-03-21 01:20:23 · 73 阅读 · 0 评论 -
LeetCode 153 - Find Minimum in Rotated Sorted Array
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 the ar...原创 2015-02-21 11:21:45 · 53 阅读 · 0 评论 -
LeetCode - Search for a Range
Given a sorted array of integers, 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...原创 2015-01-13 03:48:17 · 67 阅读 · 0 评论 -
LeetCode - Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function to determine if a given target is in the a...原创 2015-01-10 09:42:36 · 53 阅读 · 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. ...原创 2015-05-03 01:39:42 · 48 阅读 · 0 评论