From a86abdfd9a9d9b675b5bb8264763ba0d2186109e Mon Sep 17 00:00:00 2001 From: ductnn Date: Sat, 1 Jun 2024 23:58:10 +0700 Subject: [PATCH] add sol --- leetcode/3110.ScoreofaString/sol.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 leetcode/3110.ScoreofaString/sol.go 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)) +}