2365. Percentage of Letter in String
My accepted C++ solution to LeetCode problem 2365, Percentage of Letter in String, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 8.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 8.2MB, accepted 2025-12-27.
class Solution {
public:
int percentageLetter(string s, char letter) {
int count = 0;
for (char c : s) if (c == letter) count++;
return count * 100 / s.size();
}
};