Skip to content

Commit 2da6e71

Browse files
committed
Add solution #434
1 parent 2b5927b commit 2da6e71

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
414|[Third Maximum Number](./0414-third-maximum-number.js)|Easy|
253253
415|[Add Strings](./0415-add-strings.js)|Easy|
254254
419|[Battleships in a Board](./0419-battleships-in-a-board.js)|Medium|
255+
434|[Number of Segments in a String](./0434-number-of-segments-in-a-string.js)|Easy|
255256
435|[Non-overlapping Intervals](./0435-non-overlapping-intervals.js)|Medium|
256257
437|[Path Sum III](./0437-path-sum-iii.js)|Medium|
257258
442|[Find All Duplicates in an Array](./0442-find-all-duplicates-in-an-array.js)|Medium|
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* 434. Number of Segments in a String
3+
* https://leetcode.com/problems/number-of-segments-in-a-string/
4+
* Difficulty: Easy
5+
*
6+
* Given a string s, return the number of segments in the string.
7+
*
8+
* A segment is defined to be a contiguous sequence of non-space characters.
9+
*/
10+
11+
/**
12+
* @param {string} s
13+
* @return {number}
14+
*/
15+
var countSegments = function(s) {
16+
return s.split(/\s+/).filter(s => s).length;
17+
};

0 commit comments

Comments
 (0)