1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/go/score-of-a-string.go
Matej Focko d2ef757754
go: allow testing
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-16 11:44:08 +02:00

15 lines
205 B
Go

package main
func scoreOfString(s string) int {
abs := func(x int) int {
return max(x, -x)
}
score := 0
for i := 0; i+1 < len(s); i++ {
score += abs(int(s[i]) - int(s[i+1]))
}
return score
}