#1869

Longer Contiguous Segments of Ones than Zeros

pupil · 355 · lc easy +23 · verified · 62.3% accepted · 573 likes · top 63%

Description

Given a binary string s, return true if the longest consecutive run of 1s is strictly longer than the longest consecutive run of 0s, and false otherwise. If a character does not appear, its longest run is treated as 0.

Example 1:

Input: s = "1101"
Output: true
Explanation:
The longest contiguous segment of 1s has length 2: "1101"
The longest contiguous segment of 0s has length 1: "1101"
The segment of 1s is longer, so return true.

Example 2:

Input: s = "111000"
Output: false
Explanation:
The longest contiguous segment of 1s has length 3: "111000"
The longest contiguous segment of 0s has length 3: "111000"
The segment of 1s is not longer, so return false.

Example 3:

Input: s = "110100010"
Output: false
Explanation:
The longest contiguous segment of 1s has length 2: "110100010"
The longest contiguous segment of 0s has length 3: "110100010"
The segment of 1s is not longer, so return false.

Code

1
2
3