Skip to content

Commit b75523d

Browse files
committed
Added reverse the words in a string program
1 parent f3dabfe commit b75523d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: reverse_words_of_string.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
This is Leetcode question: https://leetcode.com/problems/reverse-words-in-a-string/
3+
4+
"""
5+
6+
def reverseWords(s: str) -> str:
7+
s = s.split()
8+
s.reverse()
9+
return " ".join(s)
10+
11+
12+
assert reverseWords(" Hello World ")=="World Hello"
13+
assert reverseWords("a good example")=="example good a"
14+
assert reverseWords("okay")=="okay"

0 commit comments

Comments
 (0)