Skip to content

Commit 5efbce1

Browse files
authored
Create score-of-a-string.py
1 parent 00704fb commit 5efbce1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Python/score-of-a-string.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# string
5+
class Solution(object):
6+
def scoreOfString(self, s):
7+
"""
8+
:type s: str
9+
:rtype: int
10+
"""
11+
return sum(abs(ord(s[i+1])-ord(s[i])) for i in xrange(len(s)-1))

0 commit comments

Comments
 (0)