Practice #5
Lección 14 de 14 del curso Tablas Hash - Serie de Estructuras de Datos #4 de Coddy.
Desafío
FácilEscribe una función firstNonRepeating que reciba un arreglo de enteros arr y devuelva el primer elemento que aparezca exactamente una vez (en orden de escaneo).
Si todos los elementos se repiten, devuelve -1.
Debes utilizar la clase HashMap proporcionada en hashmap.<ext> — no utilices elementos integrados del lenguaje como sets, dicts o maps.
Pruébalo tú mismo
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "solution.h"
int main() {
char line[8192];
if (!fgets(line, sizeof(line), stdin)) line[0] = '\0';
int arr[4096];
int n = 0;
char* tok = strtok(line, " \t\r\n");
while (tok) { arr[n++] = atoi(tok); tok = strtok(NULL, " \t\r\n"); }
int r = firstNonRepeating(arr, n);
printf("%d\n", r);
return 0;
}