题目链接
https://leetcode-cn.com/problems/reverse-prefix-of-word/solution/fan-zhuan-dan-ci-qian-zhui-by-leetcode-s-ruaj/
题解
rt
class Solution {
public:
string reversePrefix(string word, char ch) {
string s = "";
int i = 0;
for(;i<word.length();i++)
{
s.push_back(word[i]);
if(word[i] == ch) break;
}
if(i == word.length()) return s;
reverse(s.begin(), s.end());
return s + word.substr(i+1, word.length() - (i+1));
}
};