Skip to content

Instantly share code, notes, and snippets.

@ilpropheta
Last active July 12, 2016 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilpropheta/b9db551c7b9683cac47f96ba8641aab2 to your computer and use it in GitHub Desktop.
Save ilpropheta/b9db551c7b9683cac47f96ba8641aab2 to your computer and use it in GitHub Desktop.
const auto mid = next(begin(S), S.size()/2); // we'll reuse it
const auto diffIt = mismatch(begin(S), mid, rbegin(S)).first;
const auto diffIdx = distance(begin(S), diffIt); // diffIt as 0-based position
if (equal(next(diffIt), mid, next(rbegin(S), diffIdx)))
cout << diffIdx << endl;
else
cout << S.size() - diffIdx - 1 << endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment