mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个二进制字符串 <code>s</code>(仅由 '0' 和 '1' 组成的字符串)。</p>
 | 
						||
 | 
						||
<p>返回所有字符都为 1 的子字符串的数目。</p>
 | 
						||
 | 
						||
<p>由于答案可能很大,请你将它对 10^9 + 7 取模后返回。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>s = "0110111"
 | 
						||
<strong>输出</strong>:9
 | 
						||
<strong>解释:</strong>共有 9 个子字符串仅由 '1' 组成
 | 
						||
"1" -> 5 次
 | 
						||
"11" -> 3 次
 | 
						||
"111" -> 1 次</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>s = "101"
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>子字符串 "1" 在 s 中共出现 2 次
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>s = "111111"
 | 
						||
<strong>输出:</strong>21
 | 
						||
<strong>解释:</strong>每个子字符串都仅由 '1' 组成
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 4:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>s = "000"
 | 
						||
<strong>输出:</strong>0
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>s[i] == '0'</code> 或 <code>s[i] == '1'</code></li>
 | 
						||
	<li><code>1 <= s.length <= 10^5</code></li>
 | 
						||
</ul>
 |