array and hashmap
January 16, 2023
Percentage of letter in string
We will count the number of occurance of the letter in the string, and then calculate the percentage of the given letter.
class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return int((s.count(letter) / len(s)) * 100)
Time complexity: O(n), n is the length of the string.
Space complexity: O(1)