Reverse Prefix of Word

PHOTO EMBED

Sat Oct 08 2022 19:36:10 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

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

https://leetcode.com/problems/reverse-prefix-of-word/