Skip to content

Commit daeb078

Browse files
author
binbin.hou
committed
[Feature] add for new
1 parent 7ba72dc commit daeb078

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: LC151. 反转字符串中的单词 reverse-words-in-a-string
3+
date: 2025-11-17
4+
categories: [TopInterview150]
5+
tags: [leetcode, topInterview150, array, sort]
6+
published: true
7+
---
8+
9+
# LC151. 反转字符串中的单词 reverse-words-in-a-string
10+
11+
给你一个字符串 s ,请你反转字符串中 单词 的顺序。
12+
13+
单词 是由非空格字符组成的字符串。s 中使用至少一个空格将字符串中的 单词 分隔开。
14+
15+
返回 单词 顺序颠倒且 单词 之间用单个空格连接的结果字符串。
16+
17+
注意:输入字符串 s中可能会存在前导空格、尾随空格或者单词间的多个空格。返回的结果字符串中,单词间应当仅用单个空格分隔,且不包含任何额外的空格。
18+
19+
示例 1:
20+
21+
输入:s = "the sky is blue"
22+
输出:"blue is sky the"
23+
24+
25+
示例 2:
26+
27+
输入:s = " hello world "
28+
输出:"world hello"
29+
解释:反转后的字符串中不能存在前导空格和尾随空格。
30+
31+
32+
示例 3:
33+
34+
输入:s = "a good example"
35+
输出:"example good a"
36+
解释:如果两个单词间有多余的空格,反转后的字符串需要将单词间的空格减少到仅有一个。
37+
38+
39+
提示:
40+
41+
1 <= s.length <= 10^4
42+
43+
s 包含英文大小写字母、数字和空格 ' '
44+
45+
s 中 至少存在一个 单词
46+
47+
进阶:如果字符串在你使用的编程语言中是一种可变数据类型,请尝试使用 O(1) 额外空间复杂度的 原地 解法。
48+
49+
50+
# v1-暴力
51+
52+
53+
...
54+
55+
56+
# 开源地址
57+
58+
为了便于大家学习,所有实现均已开源。欢迎 fork + star~
59+
60+
> 笔记 [https://github.com/houbb/leetcode-notes](https://github.com/houbb/leetcode-notes)
61+
62+
> 源码 [https://github.com/houbb/leetcode](https://github.com/houbb/leetcode)
63+
64+
65+
# 参考资料
66+
67+
https://leetcode.cn/problems/jump-game-ix/solutions/3762167/jie-lun-ti-pythonjavacgo-by-endlesscheng-x2qu/

0 commit comments

Comments
 (0)