class Solution
{
public:
void Reverse(string& s, int start, int end)
{
while (start < end)
{
swap(s[start], s[end]);
start++;
end--;
}
}
string reverseWords(string s)
{
size_t index = 0;
size_t pos = 0;
while (index < s.size())
{
pos = s.find(' ', index);
if (pos == string::npos)
{
pos = s.size();
Reverse(s, index, pos - 1);
break;
}
Reverse(s, index, pos - 1);
index = pos + 1;
}
return s;
}
};
03-06
163
09-10
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交