-
-
Save ilpropheta/b9db551c7b9683cac47f96ba8641aab2 to your computer and use it in GitHub Desktop.
This file contains 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
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