Created
February 25, 2017 06:27
-
-
Save hikilaka/9cb713d9046d566cc003713cd3f33566 to your computer and use it in GitHub Desktop.
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
std::string reverseParentheses(std::string s) { | |
auto range_start = s.find_last_of('('); | |
auto range_end = s.find(')', range_start); | |
if (range_start == std::string::npos || range_end == std::string::npos) { | |
return s; | |
} | |
auto begin = std::begin(s); | |
auto end = std::begin(s); | |
std::advance(begin, range_start + 1); | |
std::advance(end, range_end); | |
std::reverse(begin, end); | |
s.erase(range_start, 1); | |
s.erase(range_end - 1, 1); | |
return reverseParentheses(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment