Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
Created June 21, 2019 04:09
Show Gist options
  • Save dgodfrey206/288f4a77e1dd17ca4aa4124d42e1fd4d to your computer and use it in GitHub Desktop.
Save dgodfrey206/288f4a77e1dd17ca4aa4124d42e1fd4d to your computer and use it in GitHub Desktop.
New consecutive_find. More efficient
int consecutive_find(vector<int> arr, int n) {
for (size_t s = 0, e = 0; e < arr.size(); s = e) {
while (e < arr.size() && arr[s] == arr[e]) {
e++;
}
if (e - s == (size_t)n) {
return s;
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment