Skip to content

Commit a6565b6

Browse files
authored
feat: add javascript solution to lc problem: No.1869.Longer Contiguous Segments of Ones than Zeros (doocs#402)
1 parent 57743e2 commit a6565b6

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,31 @@ class Solution {
114114
}
115115
```
116116

117+
### **JavaScript**
118+
119+
```js
120+
/**
121+
* @param {string} s
122+
* @return {boolean}
123+
*/
124+
var checkZeroOnes = function(s) {
125+
let max0 = 0, max1 = 0;
126+
let t0 = 0, t1 = 0;
127+
for (let char of s) {
128+
if (char == '0') {
129+
t0++;
130+
t1 = 0;
131+
} else {
132+
t1++;
133+
t0 = 0;
134+
}
135+
max0 = Math.max(max0, t0);
136+
max1 = Math.max(max1, t1);
137+
}
138+
return max1 > max0;
139+
};
140+
```
141+
117142
### **...**
118143

119144
```

solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros/README_EN.md

+25
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,31 @@ class Solution {
100100
}
101101
```
102102

103+
### **JavaScript**
104+
105+
```js
106+
/**
107+
* @param {string} s
108+
* @return {boolean}
109+
*/
110+
var checkZeroOnes = function(s) {
111+
let max0 = 0, max1 = 0;
112+
let t0 = 0, t1 = 0;
113+
for (let char of s) {
114+
if (char == '0') {
115+
t0++;
116+
t1 = 0;
117+
} else {
118+
t1++;
119+
t0 = 0;
120+
}
121+
max0 = Math.max(max0, t0);
122+
max1 = Math.max(max1, t1);
123+
}
124+
return max1 > max0;
125+
};
126+
```
127+
103128
### **...**
104129

105130
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var checkZeroOnes = function(s) {
6+
let max0 = 0, max1 = 0;
7+
let t0 = 0, t1 = 0;
8+
for (let char of s) {
9+
if (char == '0') {
10+
t0++;
11+
t1 = 0;
12+
} else {
13+
t1++;
14+
t0 = 0;
15+
}
16+
max0 = Math.max(max0, t0);
17+
max1 = Math.max(max1, t1);
18+
}
19+
return max1 > max0;
20+
};

0 commit comments

Comments
 (0)