Leetcode 2278 Percentage of Letter in String Solution in java | Hindi Coding Community

0

 


Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.


Example 1:


Input: s = "foobar", letter = "o"

Output: 33




public int percentageLetter(String s, char letter) {
double a = 0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)==letter) a++;
}
return (int)(100*a / s.length());
}


Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !