1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-07 00:11:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/字符串的反转度 [reverse-degree-of-a-string].html
2025-04-03 23:09:51 +08:00

110 lines
3.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个字符串 <code>s</code>,计算其 <strong>反转度</strong></p>
<p><strong>反转度</strong>的计算方法如下:</p>
<ol>
<li>对于每个字符,将其在 <strong>反转</strong> 字母表中的位置(<code>'a'</code> = 26, <code>'b'</code> = 25, ..., <code>'z'</code> = 1与其在字符串中的位置下标从<strong>1 </strong>开始)相乘。</li>
<li>将这些乘积加起来,得到字符串中所有字符的和。</li>
</ol>
<p>返回 <strong>反转度</strong></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "abc"</span></p>
<p><strong>输出:</strong> <span class="example-io">148</span></p>
<p><strong>解释:</strong></p>
<table style="border: 1px solid black;">
<tbody>
<tr>
<th style="border: 1px solid black;">字母</th>
<th style="border: 1px solid black;">反转字母表中的位置</th>
<th style="border: 1px solid black;">字符串中的位置</th>
<th style="border: 1px solid black;">乘积</th>
</tr>
<tr>
<td style="border: 1px solid black;"><code>'a'</code></td>
<td style="border: 1px solid black;">26</td>
<td style="border: 1px solid black;">1</td>
<td style="border: 1px solid black;">26</td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>'b'</code></td>
<td style="border: 1px solid black;">25</td>
<td style="border: 1px solid black;">2</td>
<td style="border: 1px solid black;">50</td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>'c'</code></td>
<td style="border: 1px solid black;">24</td>
<td style="border: 1px solid black;">3</td>
<td style="border: 1px solid black;">72</td>
</tr>
</tbody>
</table>
<p>反转度是 <code>26 + 50 + 72 = 148</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "zaza"</span></p>
<p><strong>输出:</strong> <span class="example-io">160</span></p>
<p><strong>解释:</strong></p>
<table style="border: 1px solid black;">
<tbody>
<tr>
<th style="border: 1px solid black;">字母</th>
<th style="border: 1px solid black;">反转字母表中的位置</th>
<th style="border: 1px solid black;">字符串中的位置</th>
<th style="border: 1px solid black;">乘积</th>
</tr>
<tr>
<td style="border: 1px solid black;"><code>'z'</code></td>
<td style="border: 1px solid black;">1</td>
<td style="border: 1px solid black;">1</td>
<td style="border: 1px solid black;">1</td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>'a'</code></td>
<td style="border: 1px solid black;">26</td>
<td style="border: 1px solid black;">2</td>
<td style="border: 1px solid black;">52</td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>'z'</code></td>
<td style="border: 1px solid black;">1</td>
<td style="border: 1px solid black;">3</td>
<td style="border: 1px solid black;">3</td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>'a'</code></td>
<td style="border: 1px solid black;">26</td>
<td style="border: 1px solid black;">4</td>
<td style="border: 1px solid black;">104</td>
</tr>
</tbody>
</table>
</div>
<p>反转度是 <code>1 + 52 + 3 + 104 = 160</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>s</code> 仅包含小写字母。</li>
</ul>