Skip to content

Commit 5e4d08f

Browse files
committedFeb 12, 2017
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
 

‎src/number-of-segments-in-a-string.js

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)
Please sign in to comment.