Preview:
class Solution {
public:
    string reversePrefix(string word, char ch) {
        int n=word.size();
        int r=0;
        for(int i=0;i<n;i++)
        {
            if(word[i]!=ch)
            {
                r++;
            }
            else break;
        }
        if(r==n) return word;                                                                               reverse(word.begin(),word.begin()+r+1);
        return word;
    }
};
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter