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 5e4d08f

Browse files
add: number-of-segments-in-a-string.js
1 parent 2f26845 commit 5e4d08f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.
3+
*
4+
* Please note that the string does not contain any non-printable characters.
5+
*
6+
* number-of-segments-in-a-string.js
7+
* @authors Joe Jiang (hijiangtao@gmail.com)
8+
* @date 2017年02月12日 12:50:48
9+
* @param {string} s
10+
* @return {number}
11+
*/
12+
13+
let countSegments = function(s) {
14+
s = s.trim()
15+
if (s) {
16+
let re = new RegExp(' +');
17+
return s.split(re).length;
18+
}
19+
20+
return 0;
21+
};

‎src/two-sum.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
55
*
6-
* two0sum.js
6+
* two-sum.js
77
*
88
* @param {number[]} nums
99
* @param {number} target

0 commit comments

Comments
(0)

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