String: string left rotation investigate knowledge of migration

. 1  class Solution {// idea: by completely reversing the front, back and then turned upside down, and then inverting the entire string.
2  public :
 . 3      void ReversePart ( String & STR, int Start, int End) {
 . 4          the while (Start < End) {
 . 5              the swap (STR [Start ++], STR [end-- ]);
 . 6          }
 . 7      }
 . 8      String LeftRotateString ( String STR, int n-) {
 . 9          IF (str.size () == 0 ) {
 10              return STR;
 . 11          }
12         ReversePart(str, 0, n-1);
13         ReversePart(str, n, str.size()-1);
14         ReversePart(str, 0, str.size()-1);
15         return str;
16     }
17 };

Guess you like

Origin www.cnblogs.com/icehole/p/12123616.html