java.lang.Object
g2201_2300.s2278_percentage_of_letter_in_string.Solution

public class Solution extends Object
2278 - Percentage of Letter in String.<p>Easy</p> <p>Given a string <code>s</code> and a character <code>letter</code>, return <em>the <strong>percentage</strong> of characters in</em> <code>s</code> <em>that equal</em> <code>letter</code> <em><strong>rounded down</strong> to the nearest whole percent.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;foobar&rdquo;, letter = &ldquo;o&rdquo;</p> <p><strong>Output:</strong> 33</p> <p><strong>Explanation:</strong></p> <p>The percentage of characters in s that equal the letter &lsquo;o&rsquo; is 2 / 6 * 100% = 33% when rounded down, so we return 33.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;jjjj&rdquo;, letter = &ldquo;k&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong></p> <p>The percentage of characters in s that equal the letter &lsquo;k&rsquo; is 0%, so we return 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s</code> consists of lowercase English letters.</li> <li><code>letter</code> is a lowercase English letter.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • percentageLetter

      public int percentageLetter(String s, char letter)