🔥✅💯Easiest C++ / Python3 🐍 / Java / C / Python ✅🔥☠️ Beats 💯 ✅
Intuition\n\n\n\n\n\nC++ []\nclass Solution {\npublic:\n    int scoreOfString(string s) {\n        int score = 0;\n        for(int i = 1; i < s.length(); ++i)\n
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/21b27e86-0e54-41f3-b132-ed9a82560d00_1713024254.6682923.jpeg)\n![Screenshot 2024-04-13 213305.png](https://assets.leetcode.com/users/images/e6b7fc99-52dc-4d36-a4e5-48ffe6c32bf4_1713024261.095585.png)\n![Screenshot 2024-04-13 213312.png](https://assets.leetcode.com/users/images/fa510408-1d6e-4d09-8dae-96458296d244_1713024266.032224.png)\n![Screenshot 2024-04-13 213320.png](https://assets.leetcode.com/users/images/0ba9e602-4cef-467d-ba69-6e94566c096b_1713024270.638123.png)\n![Screenshot 2024-04-13 213329.png](https://assets.leetcode.com/users/images/e792575f-a0e2-49a9-ad1e-73a1b2ee3a14_1713024275.7922623.png)\n```C++ []\nclass Solution {\npublic:\n    int scoreOfString(string s) {\n        int score = 0;\n        for(int i = 1; i < s.length(); ++i)\n            score += abs((int)s[i] - (int)s[i -1]);\n        return score;\n    }\n};\n```\n```python3 []\nclass Solution:\n    def scoreOfString(self, s: str) -> int:\n        score = 0\n        for i in range(1 , len(s)):\n            score += abs(ord(s[i]) - ord(s[i - 1]))\n        return score\n```\n```C []\nint scoreOfString(char* s) {\n    int score = 0;\n    for(int i = 1; s[i] != \'\\0\'; ++i)\n        score += abs((int)s[i] - (int)s[i -1]);\n    \n    return score;\n}\n```\n``` Java []\nclass Solution {\n    public int scoreOfString(String s) {\n        int score = 0;\n        for(int i = 1; i < s.length(); ++i)\n            score += Math.abs((int)s.charAt(i) - (int)s.charAt(i - 1));\n        return score;\n    }\n}\n```\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def scoreOfString(self, s: str) -> int:\n        score = 0\n        for i in range(1 , len(s)):\n            score += abs(ord(s[i]) - ord(s[i - 1]))\n        return score\n```
['C', 'Python', 'C++', 'Java', 'Python3']