LintCode 62 搜索旋转排序数组
2017-05-02 10:07
357 查看
题目:search
要求:
假设有一个排序的按未知的旋转轴旋转的数组(比如,0 1 2 4 5 6 7 可能成为4 5 6 7 0 1 2)。给定一个目标值进行搜索,如果在数组中找到目标值返回数组中的索引位置,否则返回-1。你可以假设数组中不存在重复的元素。
样例:
给出[4, 5, 1, 2, 3]和target=1,返回 2给出[4, 5, 1, 2, 3]和target=0,返回 -1
算法要求:
O(logN) time解题思路:
直接找,不用二分法了算法如下:
int search(vector<int> &A, int target) { // write your code here int size = A.size(); for (int i = 0; i < size; i++) { if (A[i] == target) { return i; } } return -1; }
相关文章推荐
- LintCode 62 搜索旋转排序数组
- lintcode-62-搜索旋转排序数组
- lintcode :search in rotated sorted array 搜索旋转排序数组
- LintCode:搜索旋转排序数组
- [Lintcode] 搜索旋转排序数组 II Search in Rotated Sorted Array II
- lintcode-63-搜索旋转排序数组 II
- [LintCode] 搜索旋转排序数组 Search in Rotated Sorted Array
- LintCode : 搜索旋转排序数组
- [Lintcode] Search in Rotated Sorted Array II 搜索旋转排序数组 II
- 搜索旋转排序数组 查看运行结果 ——LintCode
- LintCode 63 搜索旋转排序数组 II
- LintCode-搜索旋转排序数组 II
- LintCode:搜索旋转排序数组
- lintcode-搜索旋转排序数组-62
- lintcode-搜索旋转排序数组II-63
- 62 - 搜索旋转排序数组
- LintCode-搜索旋转排序数组
- *[Lintcode]搜索旋转排序数组
- Lintcode 搜索旋转排序数组 II
- 搜索旋转排序数组 II