[Python, Java] Elegant & Short | 1-Line | Pairwise
Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\npython []\nclass Solution:\n    def scoreOfString(self, string: str) -> int:\n        r
# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```python []\nclass Solution:\n    def scoreOfString(self, string: str) -> int:\n        return sum(abs(ord(a) - ord(b)) for a, b in pairwise(string))\n```\n```java []\npublic class Solution {\n    public int scoreOfString(String string) {\n        return java.util.stream.IntStream.range(0, string.length() - 1).map(i -> Math.abs(string.charAt(i) - string.charAt(i + 1))).sum();\n    }\n}\n```
['Python', 'Python3']