1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/go/score-of-a-string.go
Matej Focko 00e0063e1e
go: add «3110. Score of a String»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-01 21:49:14 +02:00

15 lines
218 B
Go

package score_of_a_string
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
}