💯✅🔥Easy Java ,Python3 and C++ Solution|| 1 ms ||≧◠‿◠≦✌
Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind this approach is that the score of a string is directly proportion
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this approach is that the score of a string is directly proportional to the sum of the absolute differences between adjacent characters. By iterating through the string and calculating the absolute difference between each pair of adjacent characters, we can obtain the total score of the string.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe provided code calculates the score of a given string s based on the absolute difference between adjacent characters in the string. The score is calculated by iterating through the string and adding the absolute difference between each pair of adjacent characters.\n# Complexity\n- Time complexity:O(n), where n is the length of the input string s\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int scoreOfString(String s) {\n        int res = 0;\n        \n        for(int i=0;i<s.length()-1;i++){\n            res += Math.abs(s.charAt(i) - s.charAt(i+1));\n        }\n        return res;\n    }\n}\n```\n```python3 []\nclass Solution:\n    def scoreOfString(self, s: str) -> int:\n        ans = 0\n        \n        for i in range(len(s)-1):\n            ans += abs(ord(s[i]) - ord(s[i+1]))\n        \n        return ans\n```\n```C++ []\nclass Solution {\npublic:\n    int scoreOfString(string s) {\n        int ans = 0;\n        \n        for(int i = 0; i < s.length() - 1; i++) {\n            ans += abs(s[i] - s[i+1]);\n        }\n        \n        return ans;\n    }\n};\n```\n![upvote.png](https://assets.leetcode.com/users/images/cbea7c8e-4919-45a8-b88a-1cf52cd50165_1717201805.8338335.png)\n\n
['String', 'C++', 'Java', 'Python3']