add new solutions

This commit is contained in:
Yiyang Kang 2026-02-26 17:18:02 +09:00
parent 0f5f9e331c
commit a7ff717b7a
Signed by: kkyy
SSH key fingerprint: SHA256:lJSbAzC3MvrSORdvIVK6h/3g+rVKJNzM7zq0MgA9WKY
7 changed files with 221 additions and 0 deletions

View file

@ -0,0 +1,25 @@
package q1404
func numSteps(s string) int {
steps := 0
carry := false
for i := len(s) - 1; i > 0; i-- {
switch {
case !carry && s[i] == '0':
steps++
case !carry && s[i] == '1':
steps += 2
carry = true
case carry && s[i] == '0':
steps += 2
default:
steps++
}
}
if carry {
steps++
}
return steps
}
var _ = numSteps