Class Solution
- java.lang.Object
-
- g1801_1900.s1869_longer_contiguous_segments_of_ones_than_zeros.Solution
-
public class Solution extends Object
1869 - Longer Contiguous Segments of Ones than Zeros.Easy
Given a binary string
s, returntrueif the longest contiguous segment of1‘s is strictly longer than the longest contiguous segment of0’s ins, or returnfalseotherwise.- For example, in
s = "110100010"the longest continuous segment of1s has length2, and the longest continuous segment of0s has length3.
Note that if there are no
0’s, then the longest continuous segment of0’s is considered to have a length0. The same applies if there is no1’s.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.
Constraints:
1 <= s.length <= 100s[i]is either'0'or'1'.
- For example, in
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
-
-
Method Detail
-
checkZeroOnes
public boolean checkZeroOnes(String s)
-
-