Problem
Übersetzung anzeigenReturn 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.
Einschränkungen
0 ≤ length ≤ 100,000
Beispiele
Beispiel 1
Eingabe:
text = "swiss"
Erwartete Ausgabe:
expected = 1
Eingabe:
std::string text = "swiss";
Erwartete Ausgabe:
long long expected = 1;
Eingabe:
string text = "swiss";
Erwartete Ausgabe:
long expected = 1;
Erläuterung
s repeats, w appears once at index 1.
Beispiel 2
Eingabe:
text = "aabb"
Erwartete Ausgabe:
expected = -1
Eingabe:
std::string text = "aabb";
Erwartete Ausgabe:
long long expected = -1;
Eingabe:
string text = "aabb";
Erwartete Ausgabe:
long expected = -1;
Erläuterung
Every character repeats: -1.
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.