Straightforward | C++, Python, Java
Approach\n Describe your approach to solving the problem. \nIterate through the string starting from index 1 and sum all the absolute differences (abs(s[i] - s[
# Approach\n<!-- Describe your approach to solving the problem. -->\nIterate through the string starting from index `1` and sum all the absolute differences (`abs(s[i] - s[i-1])`).\n# Code\n```C++ []\nclass Solution {\npublic:\n    int scoreOfString(string s) {\n        int sum = 0;\n        for (int i = 1; i < s.length(); i++)\n            sum += abs(s[i] - s[i-1]);\n        return sum;\n    }\n};\n```\n```python3 []\nclass Solution:\n    def scoreOfString(self, s: str) -> int:\n        return sum(abs(ord(s[i]) - ord(s[i-1])) for i in range(1, len(s)))\n```\n```Java []\nclass Solution {\n    public int scoreOfString(String s) {\n        int sum = 0;\n        for (int i = 1; i < s.length(); i++)\n            sum += Math.abs(s.charAt(i) - s.charAt(i-1));\n        return sum;\n    }\n}\n```\n
['String', 'C', 'Python', 'C++', 'Java', 'Python3']