mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	国外版
This commit is contained in:
		
							
								
								
									
										36
									
								
								算法题(国外版)/number-of-substrings-with-only-1s.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								算法题(国外版)/number-of-substrings-with-only-1s.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
<p>Given a binary string <code>s</code>, return <em>the number of substrings with all characters</em> <code>1</code><em>'s</em>. Since the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> s = "0110111"
 | 
			
		||||
<strong>Output:</strong> 9
 | 
			
		||||
<strong>Explanation:</strong> There are 9 substring in total with only 1's characters.
 | 
			
		||||
"1" -> 5 times.
 | 
			
		||||
"11" -> 3 times.
 | 
			
		||||
"111" -> 1 time.</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 2:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> s = "101"
 | 
			
		||||
<strong>Output:</strong> 2
 | 
			
		||||
<strong>Explanation:</strong> Substring "1" is shown 2 times in s.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 3:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> s = "111111"
 | 
			
		||||
<strong>Output:</strong> 21
 | 
			
		||||
<strong>Explanation:</strong> Each substring contains only 1's characters.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Constraints:</strong></p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
 | 
			
		||||
	<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
 | 
			
		||||
</ul>
 | 
			
		||||
		Reference in New Issue
	
	Block a user