调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给你一个二进制字符串 s

请你统计并返回其中 1 显著 的数量。

如果字符串中 1 的数量 大于或等于 0 的数量的 平方,则认为该字符串是一个 1 显著 的字符串 。

 

示例 1:

输入:s = "00011"

输出:5

解释:

1 显著的子字符串如下表所示。

ijs[i..j]0 的数量1 的数量
33101
44101
230111
341102
2401112

示例 2:

输入:s = "101101"

输出:16

解释:

1 不显著的子字符串如下表所示。

总共有 21 个子字符串,其中 5 个是 1 不显著字符串,因此有 16 个 1 显著子字符串。

ijs[i..j]0 的数量1 的数量
11010
44010
14011022
041011023
150110123

 

提示:

  • 1 <= s.length <= 4 * 104
  • s 仅包含字符 '0''1'
通过次数
3K
提交次数
10.9K
通过率
27.5%


相关企业

提示 1
Let us fix the starting index l of the substring and count the number of indices r such that l <= r and the substring s[l..r] has dominant ones.

提示 2
A substring with dominant ones has at most sqrt(n) zeros.

提示 3
We cannot iterate over every r and check if the s[l..r] has dominant ones. Instead, we iterate over the next sqrt(n) zeros to the left of l and count the number of substrings with dominant ones where the current zero is the rightmost zero of the substring.

相似题目

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
s =
"00011"
Source