blob: 5de786e39a355ef5cafd489535c08fb15149d239 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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"))
|