Skip to content

Commit 757b519

Browse files
authored
Create rearrange-words-in-a-sentence.py
1 parent 79234c9 commit 757b519

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def arrangeWords(self, text):
6+
"""
7+
:type text: str
8+
:rtype: str
9+
"""
10+
result = text.split()
11+
result[0] = result[0].lower()
12+
result.sort(key=len)
13+
result[0] = result[0].title()
14+
return " ".join(result)

0 commit comments

Comments
 (0)