mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			26 lines
		
	
	
		
			889 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			889 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given a binary string <code>s</code> <strong>without leading zeros</strong>, return <code>true</code> <em>if </em><code>s</code><em> contains <strong>at most one contiguous segment of ones</strong></em>. Otherwise, return <code>false</code>.</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
<p><strong>Example 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>Input:</strong> s = "1001"
 | 
						||
<strong>Output:</strong> false
 | 
						||
<strong>Explanation: </strong>The ones do not form a contiguous segment.
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>Example 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>Input:</strong> s = "110"
 | 
						||
<strong>Output:</strong> true</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
<p><strong>Constraints:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= s.length <= 100</code></li>
 | 
						||
	<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
 | 
						||
	<li><code>s[0]</code> is <code>'1'</code>.</li>
 | 
						||
</ul>
 |