File tree 3 files changed +70
-0
lines changed
solution/1800-1899/1869.Longer Contiguous Segments of Ones than Zeros
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,31 @@ class Solution {
114
114
}
115
115
```
116
116
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
+
117
142
### ** ...**
118
143
119
144
```
Original file line number Diff line number Diff line change @@ -100,6 +100,31 @@ class Solution {
100
100
}
101
101
```
102
102
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
+
103
128
### ** ...**
104
129
105
130
```
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments