mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-05 22:59:31 +08:00
Update
This commit is contained in:
@ -16,7 +16,7 @@ LeetCode 最强题解(持续更新中):
|
||||
|[0059.螺旋矩阵II](https://github.com/youngyangyang04/leetcode/blob/master/problems/0059.螺旋矩阵II.md) |数组 |中等|**模拟**|
|
||||
|[0083.删除排序链表中的重复元素](https://github.com/youngyangyang04/leetcode/blob/master/problems/0083.删除排序链表中的重复元素.md) |链表 |简单|**模拟**|
|
||||
|[0142.环形链表II](https://github.com/youngyangyang04/leetcode/blob/master/problems/0142.环形链表II.md) |链表 |中等|**快慢指针/双指针**|
|
||||
|[0151.翻转字符串里的单词](https://github.com/youngyangyang04/leetcode/blob/master/problems/0151.翻转字符串里的单词.md) |字符串 |中等|**模拟**|
|
||||
|[0151.翻转字符串里的单词](https://github.com/youngyangyang04/leetcode/blob/master/problems/0151.翻转字符串里的单词.md) |字符串 |中等|**模拟/双指针**|
|
||||
|[0202.快乐数](https://github.com/youngyangyang04/leetcode/blob/master/problems/0202.快乐数.md) |哈希表 |简单|**哈希**|
|
||||
|[0203.移除链表元素](https://github.com/youngyangyang04/leetcode/blob/master/problems/0203.移除链表元素.md) |链表 |简单|**模拟** **虚拟头结点**|
|
||||
|[0205.同构字符串](https://github.com/youngyangyang04/leetcode/blob/master/problems/0205.同构字符串.md) |哈希表 |简单| **哈希**|
|
||||
|
BIN
pics/151_翻转字符串里的单词.png
Normal file
BIN
pics/151_翻转字符串里的单词.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
@ -48,17 +48,19 @@ public:
|
||||
s.erase(s.begin() + i);
|
||||
}
|
||||
}
|
||||
// 删除字符串最后面的空格
|
||||
if (s.size() > 0 && s[s.size() - 1] == ' ') {
|
||||
s.erase(s.begin() + s.size() - 1);
|
||||
}
|
||||
// 删除字符串最前面的空格
|
||||
if (s.size() > 0 && s[0] == ' ') {
|
||||
s.erase(s.begin());
|
||||
}
|
||||
}
|
||||
|
||||
string reverseWords(string s) {
|
||||
reverse(s, 0, s.size() - 1); // 将字符串全部反转
|
||||
removeExtraSpaces(s); // 去掉冗余空格
|
||||
reverse(s, 0, s.size() - 1); // 将字符串全部反转
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
bool entry = false;
|
||||
|
Reference in New Issue
Block a user