Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.11 KB

_3110. Score of a String.md

File metadata and controls

53 lines (39 loc) · 1.11 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 01, 2024

Last updated : July 01, 2024


Related Topics : String

Acceptance Rate : 92.78 %


Solutions

Java

class Solution {
    public int scoreOfString(String s) {
        int output = 0;
        char[] temp = s.toCharArray();
        for (int i = 0; i < temp.length - 1; i++) {
            output += Math.abs((temp[i] - temp[i + 1]));
        } 

        return output;
    }
}

Python

class Solution:
    def scoreOfString(self, s: str) -> int:
        output = 0

        for i in range(0, len(s) - 1) :
            output += abs(ord(s[i]) - ord(s[i + 1]))
        
        return output