Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 495 Bytes

File metadata and controls

23 lines (19 loc) · 495 Bytes

LeetCode Records - Question 2278 Percentage of Letter in String

Attempt 1: Use a loop

class Solution {
    public int percentageLetter(String s, char letter) {
        int count = 0;
        char[] arr = s.toCharArray();

        for (char ch : arr) {
            if (ch == letter) {
                count++;
            }
        }

        return count * 100 / arr.length;
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 41.33 MB (Beats: 34.78%)