标签:style string str == start public return int i++
1 class Solution { 2 public://思路为先翻转整个字符串,再翻转每一个单词 3 void ReverseWord(string &str, int start, int end){//传引用!!!!不能传值,致命错误!! 4 while(start < end){ 5 swap(str[start++], str[end--]); 6 } 7 } 8 string ReverseSentence(string str) { 9 ReverseWord(str,0,str.size()-1); 10 int i = 0; 11 int start = 0; 12 int end = 0; 13 while(i < str.size()){ 14 while(str[i] == ‘ ‘ && i < str.size()){ 15 i++; 16 } 17 end = start = i; 18 while(str[i] != ‘ ‘ && i < str.size()){ 19 i++; 20 end++; 21 } 22 ReverseWord(str, start, end-1);//end -1很重眼 23 } 24 return str; 25 } 26 };
标签:style string str == start public return int i++
原文地址:https://www.cnblogs.com/icehole/p/12123560.html