JAVA Easy Solution [ 99.91% ]
Approach\n- Initialize a variable sum to keep track of the score.\n- If the input string s is empty, return 0.\n- If the length of s is 1, return the ASCII valu
# Approach\n- Initialize a variable `sum` to keep track of the score.\n- If the input string `s` is empty, return 0.\n- If the length of `s` is 1, return the ASCII value of the only character.\n- Iterate over the characters of the string starting from the second character (index 1).\n- Calculate the absolute difference between the ASCII values of the current character and the previous character.\n- Add the absolute difference to the `sum`.\n- Return the final value of `sum` as the score of the string.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public int scoreOfString(String s) {\n        int sum=0;\n        if(s.length() == 0) return 0;\n        if(s.length() == 1) return (s.charAt(0));\n        for(int i=1; i<s.length(); i++){\n            sum+=Math.abs((s.charAt(i-1))-(s.charAt(i)));\n        }\n        return sum;\n    }\n}\n```\n\n![193730892e8675ebafc11519f6174bee5c4a5ab0.jpeg](https://assets.leetcode.com/users/images/93e51f2f-167f-4e18-af35-bc2862215409_1718521490.1499481.jpeg)\n
['Java']