leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

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