█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6978

Problema 0x5c - Decir si hay una letra repetida

  • Autor: andres
  • Fecha: 2023-04-18 07:11:52 UTC (Hace alrededor de 1 año)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.12 s 13 KBi
#2
Correcto
0.102 s 13 KBi
#3
Correcto
0.107 s 13 KBi
#4
Correcto
0.118 s 13 KBi
#5
Correcto
0.112 s 13 KBi
#6
Correcto
0.073 s 16 KBi
#7
Correcto
0.093 s 13 KBi
#8
Correcto
0.099 s 13 KBi
#9
Correcto
0.121 s 13 KBi
#10
Correcto
0.093 s 16 KBi
#11
Correcto
0.106 s 13 KBi
#12
Correcto
0.109 s 13 KBi
Puntos totales: 100 / 100

Código

import java.util.HashMap;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        HashMap<Character, Integer> map = new HashMap<>();
        boolean repeated = false;

        String text;
        text = scan.nextLine();

        scan.close();

        for (int i = 0; i < text.length(); i++) {
            char current = text.charAt(i);

            if (!map.containsKey(current)) {
                map.put(current, i);
            } else {
                repeated = true;
            }
        }

        if (repeated) {
            System.out.println("yes");
        } else {
            System.out.println("no");
        }
    }
}