Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3234 - Count the Number of Substrings With Dominant Ones\.

    Medium

    You are given a binary string s.

    Return the number of substrings with dominant ones.

    A string has dominant ones if the number of ones in the string is greater than or equal to the square of the number of zeros in the string.

    Example 1:

    Input: s = "00011"

    Output: 5

    Explanation:

    The substrings with dominant ones are shown in the table below.

    Example 2:

    Input: s = "101101"

    Output: 16

    Explanation:

    The substrings with non-dominant ones are shown in the table below.

    Since there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones.

    Constraints:

    • <code>1 <= s.length <= 4 * 10<sup>4</sup></code>

    • s consists only of characters '0' and '1'.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer numberOfSubstrings(String s)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait