Skip to content

Commit ab57d30

Browse files
committed
Add solution #557
1 parent 942503a commit ab57d30

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
506|[Relative Ranks](./0506-relative-ranks.js)|Easy|
115115
541|[Reverse String II](./0541-reverse-string-ii.js)|Easy|
116116
551|[Student Attendance Record I](./0551-student-attendance-record-i.js)|Easy|
117+
557|[Reverse Words in a String III](./0557-reverse-words-in-a-string-iii.js)|Easy|
117118
565|[Array Nesting](./0565-array-nesting.js)|Medium|
118119
566|[Reshape the Matrix](./0566-reshape-the-matrix.js)|Easy|
119120
606|[Construct String from Binary Tree](./0606-construct-string-from-binary-tree.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* 557. Reverse Words in a String III
3+
* https://leetcode.com/problems/reverse-words-in-a-string-iii/
4+
* Difficulty: Easy
5+
*
6+
* Given a string s, reverse the order of characters in each word within a sentence while
7+
* still preserving whitespace and initial word order.
8+
*/
9+
10+
/**
11+
* @param {string} str
12+
* @return {string}
13+
*/
14+
var reverseWords = function(str) {
15+
return str.split(/\s/).map(s => s.split('').reverse().join('')).join(' ');
16+
};

0 commit comments

Comments
 (0)