更新力扣链接

This commit is contained in:
programmercarl
2022-06-27 09:58:45 +08:00
parent 812aeeda30
commit 1b16a934d6
167 changed files with 189 additions and 189 deletions

View File

@@ -10,7 +10,7 @@
# 151.翻转字符串里的单词
[力扣题目链接](https://leetcode-cn.com/problems/reverse-words-in-a-string/)
[力扣题目链接](https://leetcode.cn/problems/reverse-words-in-a-string/)
给定一个字符串,逐个翻转字符串中的每个单词。
@@ -234,7 +234,7 @@ public:
}
void removeExtraSpaces(string& s) {//去除所有空格并在相邻单词之间添加空格, 快慢指针。
int slow = 0; //整体思想参考Leetcode: 27. 移除元素https://leetcode-cn.com/problems/remove-element/
int slow = 0; //整体思想参考Leetcode: 27. 移除元素https://leetcode.cn/problems/remove-element/
for (int i = 0; i < s.size(); ++i) { //
if (s[i] != ' ') { //遇到非空格就处理,即删除所有空格。
if (slow != 0) s[slow++] = ' '; //手动控制空格给单词之间添加空格。slow != 0说明不是第一个单词需要在单词前添加空格。