diff options
Diffstat (limited to 'score_of_string.py')
-rw-r--r-- | score_of_string.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/score_of_string.py b/score_of_string.py new file mode 100644 index 0000000..5de786e --- /dev/null +++ b/score_of_string.py @@ -0,0 +1,22 @@ +# 3110. Score of a String + +""" +you are given a string 's'. the score of a string is defined as the sume of +the absolute different between the ascii values of adjacent characters. +return the score of 's'. +""" + + +class Solution(object): + def scoreOfString(self, s): + """ + :type s: str + :rtype: int + """ + return sum(abs(ord(s[i]) - ord(s[i + 1])) for i in range(len(s) - 1)) + + +if __name__ == "__main__": + obj = Solution() + print(obj.scoreOfString("hello")) + print(obj.scoreOfString("zaz")) |