Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 20 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jul 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
607e4eb
更新 哈希表理论基础 排版格式修复
jinbudaily Jul 19, 2023
c628aa6
更新 0242.有效的字母异位词 排版格式修复
jinbudaily Jul 19, 2023
19dfa98
更新 0349.两个数组的交集 排版格式修复
jinbudaily Jul 19, 2023
764b3e9
更新 0202.快乐数 排版格式修复
jinbudaily Jul 19, 2023
23950d1
更新 001.两数之和 排版格式修复
jinbudaily Jul 19, 2023
2948791
更新 0454.四数相加II 排版格式修复
jinbudaily Jul 19, 2023
0922ede
更新 0383.赎金信 排版格式修复
jinbudaily Jul 19, 2023
eb2cdf2
更新 0015.三数之和 排版格式修复
jinbudaily Jul 19, 2023
3fe673d
更新 0018.四数之和 排版格式修复
jinbudaily Jul 19, 2023
ddee6ad
更新 哈希表总结 排版格式修复
jinbudaily Jul 19, 2023
4ae8843
Merge branch 'master' of github.com:jinbudaily/leetcode-master
jinbudaily Jul 19, 2023
00ef608
更新 0344.反转字符串 排版格式修复
jinbudaily Jul 19, 2023
5cb2501
更新 0541.反转字符串 排版格式修复
jinbudaily Jul 19, 2023
963eb8f
更新 剑指Offer05.替换空格 排版格式修复
jinbudaily Jul 19, 2023
e70ca92
更新 0151.反转字符串中的单词 排版格式修复
jinbudaily Jul 19, 2023
370a4d1
更新 剑指Offer58-II.左旋转字符串 排版格式修复
jinbudaily Jul 19, 2023
5acebcc
更新 0028.实现strStr 排版格式修复
jinbudaily Jul 19, 2023
202dd38
更新 0459.重复的字符串 排版格式修复
jinbudaily Jul 19, 2023
4fe1f08
更新 字符串总结 排版格式修复
jinbudaily Jul 19, 2023
406cada
Merge pull request #2191 from jinbudaily/master
youngyangyang04 Jul 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
更新 0151.反转字符串中的单词 排版格式修复
  • Loading branch information
jinbudaily committed Jul 19, 2023
commit e70ca923440e656d4c62761fcff2ff40e9c17b32
29 changes: 16 additions & 13 deletions problems/0151.翻转字符串里的单词.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
输出: "example good a"
解释: 如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。

## 算法公开课

# 思路
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[字符串复杂操作拿捏了! | LeetCode:151.翻转字符串里的单词](https://www.bilibili.com/video/BV1uT41177fX),相信结合视频再看本篇题解,更有助于大家对本题的理解**。

针对本题,我录制了视频讲解:[字符串复杂操作拿捏了! | LeetCode:151.翻转字符串里的单词](https://www.bilibili.com/video/BV1uT41177fX),结合本题解一起看,事半功倍!
## 思路

**这道题目可以说是综合考察了字符串的多种操作。**

Expand Down Expand Up @@ -204,8 +205,7 @@ public:

## 其他语言版本


Java:
### Java:

```Java
class Solution {
Expand Down Expand Up @@ -433,9 +433,10 @@ class Solution {
}
```

python:
### python:
(版本一)先删除空白,然后整个反转,最后单词反转。
**因为字符串是不可变类型,所以反转单词的时候,需要将其转换成列表,然后通过join函数再将其转换成列表,所以空间复杂度不是O(1)**

```Python
class Solution:
def reverseWords(self, s: str) -> str:
Expand Down Expand Up @@ -467,7 +468,7 @@ class Solution:
return " ".join(words)
```

Go:
### Go:

版本一:

Expand Down Expand Up @@ -571,7 +572,8 @@ func reverse(b *[]byte, left, right int) {



javaScript:
### JavaScript:

```js
/**
* @param {string} s
Expand Down Expand Up @@ -630,7 +632,7 @@ function reverse(strArr, start, end) {
}
```

TypeScript:
### TypeScript:

```typescript
function reverseWords(s: string): string {
Expand Down Expand Up @@ -689,7 +691,7 @@ function reverseWords(s: string): string {
};
```

Swift:
### Swift:

```swift
func reverseWords(_ s: String) -> String {
Expand Down Expand Up @@ -766,7 +768,7 @@ func reverseWord(_ s: inout [Character]) {
}
```

Scala:
### Scala:

```scala
object Solution {
Expand Down Expand Up @@ -824,8 +826,8 @@ object Solution {
}
```

### PHP:

PHP:
```php
function reverseWords($s) {
$this->removeExtraSpaces($s);
Expand Down Expand Up @@ -872,7 +874,7 @@ function reverseString(&$s, $start, $end) {
return ;
}
```
Rust:
### Rust:

```Rust
// 根据C++版本二思路进行实现
Expand Down Expand Up @@ -924,7 +926,7 @@ pub fn remove_extra_spaces(s: &mut Vec<char>) {
}
}
```
C:
### C:

```C
// 翻转字符串中指定范围的字符
Expand Down Expand Up @@ -972,3 +974,4 @@ char * reverseWords(char * s){
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

AltStyle によって変換されたページ (->オリジナル) /