728x90
https://leetcode.com/problems/score-of-a-string
class Solution:
def scoreOfString(self, s: str) -> int:
sum = 0
for i in range(len(s)-1):
sum += abs(ord(s[i]) - ord(s[i+1]))
return sum
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 404. Sum of Left Leaves (0) | 2024.04.14 |
---|---|
[Leetcode] 3114. Latest Time You Can Obtain After Replacing Characters (0) | 2024.04.14 |
[Leetcode] 2073. Time Needed to Buy Tickets (0) | 2024.04.09 |
[Leetcode] 1700. Number of Students Unable to Eat Lunch (0) | 2024.04.08 |
[Leetcode] 678. Valid Parenthesis String (0) | 2024.04.07 |