其他分享
首页 > 其他分享> > [LeetCode 2000] 反转单词前缀

[LeetCode 2000] 反转单词前缀

作者:互联网

题目链接

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));
    }
};

标签:reverse,ch,word,string,length,2000,return,LeetCode,前缀
来源: https://blog.csdn.net/pgsld2333/article/details/122768823