Skip to content

Commit 50b57ac

Browse files
committed
add readme
1 parent ec3a56a commit 50b57ac

File tree

1 file changed

+15
-0
lines changed
  • solutions/151.Reverse_Words_in_a_String

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 151. Reverse Words in a String (Medium)
2+
3+
### **链接**
4+
题目:https://leetcode.com/problems/reverse-words-in-a-string/
5+
代码(github):https://github.com/illuz/leetcode
6+
7+
### **题意**
8+
反转句子里的单词。
9+
10+
### **分析**
11+
12+
1. **(C++)** 用 stringstream 可以很方便求出来,不过空间还是用得不少。时间复杂度 O(n),空间 O(n)。
13+
2. **(Java)**`String``trim``split` 分成字符串数组,再处理
14+
3. **(Python)** 一句话就行了。
15+
4. **(C)** 如何达到 O(1) 空间?这才是这题真正考察的地方。其实只要反转每个单词,最后再反转整个句子就行了。时间复杂度同样是 O(n)。

0 commit comments

Comments
 (0)