Solución

@frayley_4b38e1ec·18/8/2026TypeScript
solution.tsTypeScript
public class Solution {
    public String mostFrequentChar(String text) {

       Set<Character> distinctChars = new HashSet<>();
       for (char ch : text.toCharArray()) {
         distinctChars.add(ch);
       }

        long max = 0;
        char tempChar = distinctChars.iterator().next();
       for(char ca : distinctChars){
        
        System.out.println(String.valueOf(ca));
        long qty = text.chars().filter(c -> c == ca).count();
        System.out.println(qty);
        if(qty > max){
            max = qty;
            tempChar = ca;
        }

       }
        
     return String.valueOf(tempChar);
    }
}
0respuestas
Respuestas

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.