2000.cpp (361B)
1 class Solution { 2 public: 3 string reversePrefix(string word, char ch) const { 4 const int n = size(word); 5 int i; 6 7 for (i = 0; i < n; i++) { 8 if (word[i] == ch) break; 9 } 10 11 if (i == n) return word; 12 13 int j = 0; 14 while (j < i) 15 swap(word[i--], word[j++]); 16 17 return word; 18 } 19 };