Skip to content

Commit ed2a741

Browse files
authored
Create 1784-check-if-binary-string-has-at-most-one-segment-of-ones.js
1 parent 72f1999 commit ed2a741

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
const checkOnesSegment = function(s) {
6+
let res = 1
7+
for(let i = 1, len = s.length; i < len; i++) {
8+
if(s[i] === '1' && s[i - 1] === '0') res++
9+
if(s[i] === '1' && s[i - 1] === '1') continue
10+
}
11+
return res <= 1
12+
};

0 commit comments

Comments
 (0)