LeetCode 1784. Check if Binary String Has at Most One Segment of Ones
Input: s = "1001"
Output: false
Explanation: The ones do not form a contiguous segment.Input: s = "110"
Output: trueSolution:
class Solution {
public:
bool checkOnesSegment(string s) {
return s.find("01") == string::npos;
}
};PreviousLeetCode 1782. Count Pairs Of NodesNextLeetCode 1785. Minimum Elements to Add to Form a Given Sum
Last updated