add new solutions

This commit is contained in:
Yiyang Kang 2026-03-13 16:18:54 +09:00
parent f249852923
commit f297e11859
Signed by: kkyy
SSH key fingerprint: SHA256:lJSbAzC3MvrSORdvIVK6h/3g+rVKJNzM7zq0MgA9WKY
10 changed files with 373 additions and 0 deletions

View file

@ -0,0 +1,25 @@
// 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