给你一个二进制字符串 s ,该字符串 不含前导零 。
如果 s 包含 零个或一个由连续的 '1' 组成的字段 ,返回 true 。否则,返回 false 。
如果 s 中 由连续若干个 '1' 组成的字段 数量不超过 1,返回 true 。否则,返回 false 。
示例 1: 输入:s = "1001" 输出:false
解释:由连续若干个 '1' 组成的字段数量为 2,返回 false
示例 2:
输入:s = "110"
输出:true
提示:
1 <= s.length <= 100
s[i] 为 '0' 或 '1'
s[0] 为 '1'
var checkOnesSegment = function(s) {
const n = s.length
for (let i = 2; i < n; i++) {
if (s[i - 1] === '0' && s[i] === '1') return false
}
return true
};
function checkOnesSegment(s: string): boolean {
const n = s.length
for (let i = 2; i < n; i++) {
if (s[i - 1] === '0' && s[i] === '1') return false
}
return true
};
class Solution {
function checkOnesSegment($s) {
$n = strlen($s);
for ($i = 2; $i < $n; $i++) {
if ($s[$i - 1] === '0' && $s[$i] === '1') return false;
}
return true;
}
}
func checkOnesSegment(s string) bool {
n := len(s)
for i := 2; i < n; i++ {
if s[i - 1] == '0' && s[i] == '1' {
return false
}
}
return true
}
class Solution {
public boolean checkOnesSegment(String s) {
int n = s.length();
for (int i = 2; i < n; i++) {
if (s.charAt(i - 1) == '0' && s.charAt(i) == '1') return false;
}
return true;
}
}
public class Solution {
public bool CheckOnesSegment(string s) {
int n = s.Length;
for (int i = 2; i < n; i++) {
if (s[i - 1] == '0' && s[i] == '1') return false;
}
return true;
}
}
bool checkOnesSegment(char * s){
int n = strlen(s);
for (int i = 2; i < n; i++) {
if (s[i - 1] == '0' && s[i] == '1') return false;
}
return true;
}
class Solution {
public:
bool checkOnesSegment(string s) {
int n = s.size();
for (int i = 2; i < n; i++) {
if (s[i - 1] == '0' && s[i] == '1') return false;
}
return true;
}
};
class Solution:
def checkOnesSegment(self, s: str) -> bool:
for i in range(2, len(s)):
if s[i - 1] == '0' and s[i] == '1': return False
return True
var checkOnesSegment = function(s) {
return s.indexOf('01') === -1
};
function checkOnesSegment(s: string): boolean {
return s.includes('01') === false
};
class Solution {
function checkOnesSegment($s) {
return strpos($s, '01') === false;
}
}
class Solution {
function checkOnesSegment($s) {
return strstr($s, '01') === false;
}
}
func checkOnesSegment(s string) bool {
return strings.Contains(s, "01") == false
}
class Solution {
public boolean checkOnesSegment(String s) {
return s.contains("01") == false;
}
}
public class Solution {
public bool CheckOnesSegment(string s) {
return s.Contains("01") == false;
}
}
bool checkOnesSegment(char * s){
return strstr(s, "01") == false;
}
class Solution {
public:
bool checkOnesSegment(string s) {
return s.find("01") == string::npos;
}
};
class Solution:
def checkOnesSegment(self, s: str) -> bool:
return '01' not in s