python-algorithm

leetcode 3110. Score of a String

무적김두칠 2024. 4. 22. 07:19

https://leetcode.com/problems/score-of-a-string/description/

 

1
2
3
4
5
6
7
class Solution:
    def scoreOfString(self, s: str-> int:
        answer = 0
        for i in range(1len(s)):
            answer += abs(ord(s[i]) - ord(s[i-1]))
 
        return answer
cs
반응형