diff --git a/problems/0151.翻转字符串里的单词.md b/problems/0151.翻转字符串里的单词.md index ead5fa12..677a8f64 100644 --- a/problems/0151.翻转字符串里的单词.md +++ b/problems/0151.翻转字符串里的单词.md @@ -222,7 +222,42 @@ public: 效率: +```CPP +//版本二: +class Solution { +public: + void reverseWord(string& s,int start,int end){ //这个函数,Carl哥的要更清晰。 + for(int i=start;i<(end-start)/2+start;++i){ + swap(s[i],s[end-1-i+start]); + } + } + void trim(string& s){//去除所有空格并在相邻单词之间添加空格 + int slow = 0; + for(int i=0;i