1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

go: add «3110. Score of a String»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-06-01 21:49:14 +02:00
parent c66b1879eb
commit 00e0063e1e
Signed by: mfocko
GPG key ID: 7C47D46246790496

15
go/score-of-a-string.go Normal file
View file

@ -0,0 +1,15 @@
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
}