go: add «3110. Score of a String»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
c66b1879eb
commit
00e0063e1e
1 changed files with 15 additions and 0 deletions
15
go/score-of-a-string.go
Normal file
15
go/score-of-a-string.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue