
Binary Search
文章平均质量分 77
ljffdream
这个作者很懒,什么都没留下…
展开
-
【LeetCode】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 th原创 2014-12-05 17:05:33 · 263 阅读 · 0 评论 -
[Leetcode]Median of two sorted array
[题目] There 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 O(log (m+n)). [分析] [code转载 2015-06-11 09:59:15 · 618 阅读 · 0 评论 -
[Leetcode]Sorted in rotated Array 2
[题目] median 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 tar转载 2015-06-12 09:13:22 · 311 阅读 · 0 评论 -
【LeetCode】Find Minimum In Rotated Sorted Array 1 and 2
【题目】 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转载 2015-01-05 10:20:39 · 305 阅读 · 0 评论 -
【Leetcode】Find the kth in the BST
[题目] [思路] BST的特点就是排序性,左边的节点一定比root小,右边的节点一定比root大。 另外就是二分性。 找第k个,可以先看左边树节点的个数,小于k的话,就保证了肯定是在右边。那么去找右边的k-left. k - left,就变成了新的k. 数root所在的树的节点数。这个就是用递归实现。想法就是,如果root自己本身就是null,那么就return 0; 否则至转载 2015-07-08 21:28:09 · 525 阅读 · 0 评论 -
[Leetcode]Search a 2D matrix
[timu] Search a 2D Matrix Total Accepted: 52191 Total Submissions: 164580 Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the followin原创 2015-09-02 03:29:54 · 290 阅读 · 0 评论