[leetcode, JS] 3110. Score of a String

mxxn·2024년 7월 25일
0

leetcode

목록 보기
192/198

문제

문제 링크 : Score of a String

풀이

/**
 * @param {string} s
 * @return {number}
 */
var scoreOfString = function(s) {
    let result = 0
    for(let i=0; i<s.length-1; i++) {
        result += Math.abs(s.charCodeAt(i) - s.charCodeAt(i+1))
    }

    return result
};
  1. 문자열 s의 i번째와 i+1째의 ascii 코드 차이의 절대값들을 더하는 방식
  • Runtime 47 ms, Memory 50.12 MB
profile
내일도 글쓰기

0개의 댓글