Skip to content

Commit 96288de

Browse files
committedJan 5, 2025
Add solution #3110
1 parent 43e85d7 commit 96288de

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@
384384
2627|[Debounce](./2627-debounce.js)|Medium|
385385
2629|[Function Composition](./2629-function-composition.js)|Easy|
386386
2630|[Memoize II](./2630-memoize-ii.js)|Hard|
387+
3110|[Score of a String](./3110-score-of-a-string.js)|Easy|
387388
3392|[Count Subarrays of Length Three With a Condition](./3392-count-subarrays-of-length-three-with-a-condition.js)|Easy|
388389
3396|[Minimum Number of Operations to Make Elements in Array Distinct](./3396-minimum-number-of-operations-to-make-elements-in-array-distinct.js)|Easy|
389390
3397|[Maximum Number of Distinct Elements After Operations](./3397-maximum-number-of-distinct-elements-after-operations.js)|Medium|

‎solutions/3110-score-of-a-string.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 3110. Score of a String
3+
* https://leetcode.com/problems/score-of-a-string/
4+
* Difficulty: Easy
5+
*
6+
* You are given a string s. The score of a string is defined as the sum of the absolute
7+
* difference between the ASCII values of adjacent characters.
8+
*
9+
* Return the score of s.
10+
*/
11+
12+
/**
13+
* @param {string} s
14+
* @return {number}
15+
*/
16+
var scoreOfString = function(s) {
17+
let sum = 0;
18+
for (let i = 0; i < s.length - 1; i++) {
19+
sum += Math.abs(s[i].charCodeAt() - s[i + 1].charCodeAt());
20+
}
21+
return sum;
22+
};

0 commit comments

Comments
 (0)
Please sign in to comment.