add new solutions
This commit is contained in:
parent
f249852923
commit
f297e11859
10 changed files with 373 additions and 0 deletions
25
solutions/17/q1784/solution.go
Normal file
25
solutions/17/q1784/solution.go
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue