标签:
1 class Solution { 2 public: 3 string reverse(string str,int i,int j) 4 { 5 while(i<j) 6 { 7 char tmp=str[j]; 8 str[j]=str[i]; 9 str[i]=tmp; 10 i++;j--; 11 } 12 return str; 13 } 14 string LeftRotateString(string str, int n) { 15 string s; 16 if(str.empty()) 17 return s; 18 if(n>str.size())return s; 19 s=reverse(str,0,str.size()-1); 20 s=reverse(s,0,s.size()-n-1); 21 s=reverse(s,s.size()-n,s.size()-1); 22 return s; 23 } 24 };
标签:
原文地址:http://www.cnblogs.com/daocaorenblog/p/5404951.html