From ceaaa2fd2d3114c75794b89fbb08005dd991b81c Mon Sep 17 00:00:00 2001 From: Epoch <75031971+messenger1th@users.noreply.github.com> Date: Mon, 21 Feb 2022 14:37:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200151.=E7=BF=BB=E8=BD=AC?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=87=8C=E7=9A=84=E5=8D=95=E8=AF=8D?= =?UTF-8?q?=E7=9A=84CPP=E6=9B=B4=E7=AE=80=E6=B4=81=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用LC27的原理使得更为简洁。 --- problems/0151.翻转字符串里的单词.md | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) 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