3379. Score of a String
My accepted Python solution to LeetCode problem 3379, Score of a String, running in 2ms.
- Difficulty: Easy
- Python
- Runtime 2ms
- Memory 17.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 2ms, memory 17.4MB, accepted 2026-01-01.
class Solution:
def scoreOfString(self, s: str) -> int:
return sum(abs(ord(s[i]) - ord(s[i+1])) for i in range(len(s) - 1))