[LeetCode 2000] 反转单词前缀
作者:互联网
题目链接
题解
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));
}
};
标签:reverse,ch,word,string,length,2000,return,LeetCode,前缀 来源: https://blog.csdn.net/pgsld2333/article/details/122768823