One line Solution 😱😱
It\'s a pretty simple problem! You just take a character and subtract the next character. If we convert them into integers, they get converted into their ASCII 
It\'s a pretty simple problem! You just take a character and subtract the next character. If we convert them into integers, they get converted into their ASCII values. So, if we subtract two characters, they are actually subtracted based on their ASCII values!\n\nTherefore, it\'s quite simple: you just subtract two adjacent characters and take the absolute difference. Then, you add up all these absolute differences for each pair of adjacent characters. As shown in the diagram, it\'s nothing too complicated.\n\n![image](https://assets.leetcode.com/users/images/9cac69dd-b67a-4580-bda5-9ff61da8c9ac_1717200977.6534123.png)\n\nLet me explain you the code first :\n\n1. **Initialization**: The variable `total` is initialized to 0.\n2. **Loop**: The `for` loop runs from the first character (`i = 0`) to the second last character (`i < s.length() - 1`).\n3. **Calculation**: Inside the loop, `Math.abs(s.charAt(i) - s.charAt(i + 1))` calculates the absolute difference between the ASCII values of the current character (`s.charAt(i)`) and the next character (`s.charAt(i + 1)`). This value is added to `total`.\n4. **Return**: The function returns the total score after the loop finishes.\n\n**Let\\s code it UP**\n\n### C++ Code\n```cpp\nclass Solution {\npublic:\n    int scoreOfString(string s) {\n        int total = 0;\n        for(int i = 0; i < s.size() - 1; i++) {\n            total += abs(s[i] - s[i + 1]);\n        }\n        return total;\n    }\n};\n```\n\n### Java Code\n```java\nclass Solution {\n    public int scoreOfString(String s) {\n        int total = 0;\n        for(int i = 0; i < s.length() - 1; i++) {\n            total += Math.abs(s.charAt(i) - s.charAt(i + 1));\n        }\n        return total;\n    }\n}\n```\n\n### Python Code\n```python\nclass Solution:\n    def scoreOfString(self, s: str) -> int:\n        total = 0\n        for i in range(len(s) - 1):\n            total += abs(ord(s[i]) - ord(s[i + 1]))\n        return total\n```\n\n___\nComplexity Analysis \n___\n\n* **Time Complexity :-** BigO(n)\n* **Space Complexity :-** BigO(1)\n\n___\n___\n\n**One Line Solution**\n\n\n**C++**\n\n```cpp\nclass Solution {\npublic:\n    int scoreOfString(string s) {\n        return accumulate(next(s.begin()), s.end(), 0, [&s](int total, char c, size_t i = 0) mutable {\n            return total + abs(s[i++] - c);\n        });\n    }\n};\n```\n\n**JAVA**\n\n```java\npublic class Solution {\n    public int scoreOfString(String s) {\n        return java.util.stream.IntStream.range(0, s.length() - 1).map(i -> Math.abs(s.charAt(i) - s.charAt(i + 1))).sum();\n    }\n}\n```\n\n**PYTHON**\n\n```python\nclass Solution:\n    def scoreOfString(self, s: str) -> int:\n        return sum(abs(ord(s[i]) - ord(s[i + 1])) for i in range(len(s) - 1))\n```\n
['C', 'Python', 'Java']