LeetCode 033 Search in Rotated Sorted Array

题目要求:Search 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).

You are given a target value to search. If found in the array return its index, otherwise return -1.

You may assume no duplicate exists in the array.

代码如下:

class Solution {
public:
int search(int A[], int n, int target) { int index = -1; //题目简化成找到数组A中的元素位置……
for(int i = 0; i < n; i++){
if(A[i] == target){
index = i;
break;
}
} return index;
}
};
上一篇:详解Qt,并举例说明动态编译(shared)和静态编译(static)以及debug and release 编译版本区别(可产生静态版的Debug版本,需要把-release 改为 –debug-and-release)


下一篇:《zw版·Halcon-delphi系列原创教程》 只有2行代码的超市收款单ocr脚本