Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f7c0308

Browse files
String: 434. Number of Segments in a String
1 parent 8ddd4bb commit f7c0308

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// https://leetcode.com/problems/number-of-segments-in-a-string/description/
2+
/**
3+
* 434. Number of Segments in a String
4+
* @param {string} s
5+
* @return {number}
6+
*/
7+
var countSegments = function(s) {
8+
s = s.trim();
9+
if (s.length < 1) return 0;
10+
return s.split(/\s+/g).length;
11+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /