mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
9 lines
167 B
C
9 lines
167 B
C
// 顺序查找
|
|
int SequentialSearch(vector<int>& v, int k) {
|
|
int i = 0;
|
|
for (; i < v.size(); ++i)
|
|
if (v[i] == k)
|
|
return i;
|
|
if (i == v.size())
|
|
return -1;
|
|
} |