标签:logs turn art pre eve 意思 剑指offer class font
剑指offer-翻转单词顺序列
题解:
双次翻转,先整体翻转,然后针对逐个单词翻转。
class Solution { public: string ReverseSentence(string str) { reverse(str.begin(), str.end()); int start = 0; for(int i=0; i<str.length(); ++i){ if(str[i] == ‘ ‘){ reverse(str.begin() + start, str.begin() + i); start = i + 1; }else if(i == str.length() - 1){ reverse(str.begin() + start, str.end()); } } return str; } };
标签:logs turn art pre eve 意思 剑指offer class font
原文地址:http://www.cnblogs.com/zhang-yd/p/6617186.html