diff --git a/leetcode/3110.ScoreofaString/sol.go b/leetcode/3110.ScoreofaString/sol.go new file mode 100644 index 0000000..d62d677 --- /dev/null +++ b/leetcode/3110.ScoreofaString/sol.go @@ -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)) +}