Tous les défis
Facile 0 résolus 0 % de réussite

First Unique Character

Find the first character that appears only once.

Return the index of the first character in text that appears exactly once. Case matters.

Implement first_unique_index(text).

Input

text: The text to inspect.

Output

Return the index, or -1 if every character repeats.

Contraintes

0 ≤ length ≤ 100,000

Exemples

Exemple 1
Entrée :
text = "swiss"

Sortie attendue :
expected = 1
Entrée :
std::string text = "swiss";

Sortie attendue :
long long expected = 1;
Entrée :
string text = "swiss";

Sortie attendue :
long expected = 1;

Explication

s repeats, w appears once at index 1.

Exemple 2
Entrée :
text = "aabb"

Sortie attendue :
expected = -1
Entrée :
std::string text = "aabb";

Sortie attendue :
long long expected = -1;
Entrée :
string text = "aabb";

Sortie attendue :
long expected = -1;

Explication

Every character repeats: -1.

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.