Beats 100% || abs() function || C++
\n\n# Intuition\nabs() function is used to get absolute difference between each character and its next\n\n# Approach\nRemember to iterate only till n-2, since w
![Screenshot 2024-06-01 181839.png](https://assets.leetcode.com/users/images/82d0239c-3dc6-4711-8f37-09da9e3668fa_1717246476.4011319.png)\n\n# Intuition\nabs() function is used to get absolute difference between each character and its next\n\n# Approach\nRemember to iterate only till n-2, since we we will be using i+1 index which WILL cause out of bounds if we dont limit loop till n-2\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int scoreOfString(string s) {\n        int score=0;\n        for(int i=0; i<s.size()-1; i++){\n            score=score+abs(s[i]-s[i+1]);\n        }\n        return score;\n    }\n};\n```
['C++']