LintCode 62 搜索旋转排序数组
来源:互联网 发布:成都软件培训哪家好 编辑:程序博客网 时间:2024/05/24 07:39
题目: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; }
0 0
- lintcode-搜索旋转排序数组-62
- LintCode 62 搜索旋转排序数组
- LintCode 62 搜索旋转排序数组
- LintCode-搜索旋转排序数组
- LintCode : 搜索旋转排序数组
- LintCode:搜索旋转排序数组
- LintCode:搜索旋转排序数组
- *[Lintcode]搜索旋转排序数组
- lintcode,搜索旋转排序数组
- Lintcode 搜索旋转排序数组
- lintcode--搜索旋转排序数组
- LintCode-搜索旋转排序数组 II
- LintCode : 搜索旋转排序数组 II
- lintcode-搜索旋转排序数组II-63
- LintCode:搜索旋转排序数组 II
- Lintcode 搜索旋转排序数组 II
- LintCode 63 搜索旋转排序数组 II
- LintCode:M-搜索旋转排序数组
- 你真的会使用枚举么
- HDU 5375 Gray code
- Protobuf 协议的Java应用sample
- bzoj2219 【原根】【CRT】
- sql语句优化的13种方法
- LintCode 62 搜索旋转排序数组
- python映射类型:字典---创建、更新、删除、修改等操作实例源码
- MySQL中根据if标签实现多条件模糊查询(动态SQL语句)
- Service(二)
- Android Http随笔
- 强制横屏(仅适用于present情景)
- 安卓onResume()代替EventBus刷新数据情况
- Bootstrap的引用文件
- 存储之IP SAN