File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 252
252
414|[ Third Maximum Number] ( ./0414-third-maximum-number.js ) |Easy|
253
253
415|[ Add Strings] ( ./0415-add-strings.js ) |Easy|
254
254
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|
255
256
435|[ Non-overlapping Intervals] ( ./0435-non-overlapping-intervals.js ) |Medium|
256
257
437|[ Path Sum III] ( ./0437-path-sum-iii.js ) |Medium|
257
258
442|[ Find All Duplicates in an Array] ( ./0442-find-all-duplicates-in-an-array.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments