Created
June 21, 2019 04:09
-
-
Save dgodfrey206/288f4a77e1dd17ca4aa4124d42e1fd4d to your computer and use it in GitHub Desktop.
New consecutive_find. More efficient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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