cpp-interview/Algorithm/SequentialSearch.h
2018-03-09 22:41:55 +08:00

7 lines
141 B
C

// 顺序查找
int SequentialSearch(vector<int>& v, int k) {
for (int i = 0; i < v.size(); ++i)
if (v[i] == k)
return i;
return -1;
}