Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4790837

Browse files
committed
Add solution #2129
1 parent 83440f4 commit 4790837

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

2129-capitalize-the-title.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 2129. Capitalize the Title
3+
* https://leetcode.com/problems/capitalize-the-title/
4+
* Difficulty: Easy
5+
*
6+
* You are given a string title consisting of one or more words separated by a single space,
7+
* where each word consists of English letters. Capitalize the string by changing the
8+
* capitalization of each word such that:
9+
* - If the length of the word is 1 or 2 letters, change all letters to lowercase.
10+
* - Otherwise, change the first letter to uppercase and the remaining letters to lowercase.
11+
* Return the capitalized title.
12+
*/
13+
14+
/**
15+
* @param {string} title
16+
* @return {string}
17+
*/
18+
var capitalizeTitle = function(title) {
19+
return title.split(/\s+/).map(word => {
20+
return word.toLowerCase().replace(/^\w/, l => word.length > 2 ? l.toUpperCase() : l);
21+
}).join(' ');
22+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
2095|[Delete the Middle Node of a Linked List](./2095-delete-the-middle-node-of-a-linked-list.js)|Medium|
280280
2099|[Find Subsequence of Length K With the Largest Sum](./2099-find-subsequence-of-length-k-with-the-largest-sum.js)|Medium|
281281
2114|[Maximum Number of Words Found in Sentences](./2114-maximum-number-of-words-found-in-sentences.js)|Easy|
282+
2129|[Capitalize the Title](./2129-capitalize-the-title.js)|Easy|
282283

283284
## License
284285

0 commit comments

Comments
 (0)