Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Jun 1, 2024
1 parent e17f493 commit a86abdf
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions leetcode/3110.ScoreofaString/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// https://leetcode.com/problems/score-of-a-string/description/

package main

import (
"fmt"
)

func scoreOfString(s string) int {
res := 0
for i := 1; i < len(s); i++ {
res += abs(int(s[i-1]) - int(s[i]))
}
return res
}

func abs(a int) int {
if a < 0 {
return -a
}
return a
}

func main() {
s := "zaz"
fmt.Println(scoreOfString(s))
}

0 comments on commit a86abdf

Please sign in to comment.