Search for a Range
2012-10-28 14:30
190 查看
首先我要在纸上,非常非常聪明且迅速且机灵,
给出几个用例,找出边界用例和特殊用例,确定特判条件;在编码前考虑到所有的条件
向面试官提问:问题规模,特殊用例
给出函数头
暴力解,简述,优化。
给出能够想到的最优价
伪代码,同时结合用例
真实代码
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 the array, return
For example,
Given
return
http://collabedit.com/9k2mn
pair<int, int> search_range (vector<int> arr, int x)
{
return make_pair(upper_bound(arr.begin(), arr.end(), x), lower_bound(arr.begin(), arr.end(), x));
}
给出几个用例,找出边界用例和特殊用例,确定特判条件;在编码前考虑到所有的条件
向面试官提问:问题规模,特殊用例
给出函数头
暴力解,简述,优化。
给出能够想到的最优价
伪代码,同时结合用例
真实代码
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 the array, return
[-1, -1].
For example,
Given
[5, 7, 7, 8, 8, 10]and target value 8,
return
[3, 4].
http://collabedit.com/9k2mn
pair<int, int> search_range (vector<int> arr, int x)
{
return make_pair(upper_bound(arr.begin(), arr.end(), x), lower_bound(arr.begin(), arr.end(), x));
}
相关文章推荐
- CODE 99: Search for a Range
- LeetCode - Refresh - Search for a Range
- leetcode 34: Search for a Range
- 【LeetCode】34. Search for a Range
- [leetcode-二分查找]--34. Search for a Range
- lintcode:Search for a Range
- Search for a Range [LeetCode]
- LeetCode——Search for a Range
- [LeetCode][Java] Search for a Range
- leetcode 刷题之路 21 Search for a Range
- [LeetCode] Search for a Range
- Search Insert Position,Search for a Range,Pow(x, n),Sqrt(x)
- Search for a Range
- Leetcode_34. Search for a Range
- LeetCode OJ - Search for a Range
- 34. Search for a Range
- [LeetCode34]Search for a Range
- 【leetcode】Array——Search for a Range(34)
- [leetcode刷题系列]Search for a Range
- [Leetcode] Search for a Range (Java)