0ms | 100% beat | Simple and Easy Approach
Approach\nLoop through the array and calculate difference of character at index i and i+1, loop goes all the way upto size-1, store it in varaible res and at ea
# Approach\nLoop through the array and calculate difference of character at index `i` and `i+1`, loop goes all the way upto `size-1`, store it in varaible `res` and at each iteration add the difference after taking it\'s `abs` to `res `\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int scoreOfString(string s) {\n        int res = 0;\n\n        for(int i=0; i<s.size()-1; ++i) {\n            res += abs(s[i] - s[i+1]);\n        }\n\n        return res;\n    }\n};\n```
['C++']