Check if Binary String Has at Most One Segment of Ones LeetCode solution in C++

1
class Solution {
2
public:
3
bool checkOnesSegment(string s) {
4
for (int i = 1; i < s.size(); i++) {
5
if (s[i - 1] == '0' and s[i] == '1') {
6
return false;
7
}
8
}
9
return true;
10
}
11
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0