标签:
题目来源:http://www.lintcode.com/zh-cn/problem/first-position-of-target/
可以accept的程序如下(用了STL):
1 class Solution {
2 public:
3 /**
4 * @param nums: The integer array.
5 * @param target: Target number to find.
6 * @return: The first position of target. Position starts from 0.
7 */
8 int binarySearch(vector<int> &array, int target) {
9 // write your code here
10 vector<int>::iterator p;
11 p=find(array.begin(),array.end(),target);
12 if(p!=array.end())
13 return p-array.begin();
14 else
15 return -1;
16 }
17 };
标签:
原文地址:http://www.cnblogs.com/hslzju/p/5451034.html