1869. 哪种连续子字符串更长

题目链接:https://leetcode.cn/problems/longer-contiguous-segments-of-ones-than-zeros/description/

JavaScript

执行用时分布0ms 击败100.00%使用 JavaScript 的用户
消耗内存分布54.43MB 击败49.68%使用 JavaScript 的用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @param {string} s
* @return {boolean}
*/
var checkZeroOnes = function(s) {

let maxZero = 0
let maxOne = 0
const n = s.length
for (let i = 0; i < n; i++) {
let zero = 0
let one = 0
let j = i
let k = i
while (j < n && s[j] === '1') {
one ++
j++
}
while (k < n && s[k] === '0') {
zero ++
k++
}
if (one > maxOne) {
maxOne = one
}
if (zero > maxZero) {
maxZero = zero
}
}
if (maxOne > maxZero) {
return true
}
return false
};

1869. 哪种连续子字符串更长
https://pisces34.github.io/2025/03/14/leetcode/1869/
发布于
2025年3月14日
许可协议