LEETCODE第一题
class Solution {
public:
void reverseWords(string &s) {
int len = s.size();
for(int i = 0; i <= len-1; i++){
char tmp = s[i];
s[i] = s[len-i];
s[len-i] = tmp;
}
int i1 = 0, i2 = 0, cur = 0;
for(int i = 0; i <= len-1; i++){
if(s[i] == ' '){
if(i1 == i2){
i1++;
i2++;
continue;
}else{
in_word = 0;
reverse(tmp_word.begin(), tmp_word.end());
continue;
}
}else{
if(i == len-1){
reverse(tmp_word.begin(), tmp_word.end());
}else{
in_word = 1;
tmp_word += s[i];
}
}
}
s = tmp_str;
}
};