标签:++ return 左旋转字符串 class ring int oid end ota
1 class Solution {//思路:先完全翻转前面的,再完全翻转后面的,再整个字符串反转。 2 public: 3 void ReversePart(string &str, int start, int end){ 4 while(start < end){ 5 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 };
标签:++ return 左旋转字符串 class ring int oid end ota
原文地址:https://www.cnblogs.com/icehole/p/12123616.html