Skip to content

Commit 6c39ed1

Browse files
committed
Add solution #151
1 parent 9c59d86 commit 6c39ed1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* 151. Reverse Words in a String
3+
* https://leetcode.com/problems/reverse-words-in-a-string/
4+
* Difficulty: Medium
5+
*
6+
* Given an input string, reverse the string word by word.
7+
*/
8+
9+
/**
10+
* @param {string} s
11+
* @return {string}
12+
*/
13+
var reverseWords = function(s) {
14+
return s.trim().replace(/\s+/g, ' ').split(/\s/).reverse().join(' ');
15+
};

0 commit comments

Comments
 (0)