1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/字母在字符串中的百分比 [percentage-of-letter-in-string].html
2022-05-24 20:20:53 +08:00

31 lines
984 B
HTML
Raw 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> 和一个字符 <code>letter</code> ,返回在 <code>s</code> 中等于&nbsp;<code>letter</code>&nbsp;字符所占的 <strong>百分比</strong> ,向下取整到最接近的百分比。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "foobar", letter = "o"
<strong>输出:</strong>33
<strong>解释:</strong>
等于字母 'o' 的字符在 s 中占到的百分比是 2 / 6 * 100% = 33% ,向下取整,所以返回 33 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "jjjj", letter = "k"
<strong>输出:</strong>0
<strong>解释:</strong>
等于字母 'k' 的字符在 s 中占到的百分比是 0% ,所以返回 0 。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> 由小写英文字母组成</li>
<li><code>letter</code> 是一个小写英文字母</li>
</ul>