25 lines
440 B
Go
25 lines
440 B
Go
// Package q1784 implements a solution for https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones/
|
|
package q1784
|
|
|
|
func checkOnesSegment(s string) bool {
|
|
last := 0
|
|
segments := 0
|
|
for i := range len(s) {
|
|
switch s[i] {
|
|
case '0':
|
|
last = 0
|
|
case '1':
|
|
if last == 0 {
|
|
if segments > 0 {
|
|
return false
|
|
}
|
|
segments++
|
|
}
|
|
last = 1
|
|
}
|
|
}
|
|
|
|
return segments == 1
|
|
}
|
|
|
|
var _ = checkOnesSegment
|