3110. Score of a String
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 01, 2024
Last updated : July 01, 2024
Related Topics : String
Acceptance Rate : 92.78 %
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;
}
}
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