mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
39 lines
1.6 KiB
HTML
39 lines
1.6 KiB
HTML
<p>给你一个字符串 <code>s</code> 。一个字符串的 <strong>分数</strong> 定义为相邻字符 <strong>ASCII</strong> 码差值绝对值的和。</p>
|
||
|
||
<p>请你返回 <code>s</code> 的 <strong>分数</strong> 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>s = "hello"</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>13</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><code>s</code> 中字符的 <strong>ASCII </strong>码分别为:<code>'h' = 104</code> ,<code>'e' = 101</code> ,<code>'l' = 108</code> ,<code>'o' = 111</code> 。所以 <code>s</code> 的分数为 <code>|104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13</code> 。</p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>s = "zaz"</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>50</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><code>s</code> 中字符的 <strong>ASCII </strong>码分别为:<code>'z' = 122</code> ,<code>'a' = 97</code> 。所以 <code>s</code> 的分数为 <code>|122 - 97| + |97 - 122| = 25 + 25 = 50</code> 。</p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>2 <= s.length <= 100</code></li>
|
||
<li><code>s</code> 只包含小写英文字母。</li>
|
||
</ul>
|