簡単 0件解決済み 正答率0%

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.

制約

0 ≤ length ≤ 100,000

例

例 1
入力:
text = "swiss"

期待される出力:
expected = 1
入力:
std::string text = "swiss";

期待される出力:
long long expected = 1;
入力:
string text = "swiss";

期待される出力:
long expected = 1;

解説

s repeats, w appears once at index 1.

例 2
入力:
text = "aabb"

期待される出力:
expected = -1
入力:
std::string text = "aabb";

期待される出力:
long long expected = -1;
入力:
string text = "aabb";

期待される出力:
long expected = -1;

解説

Every character repeats: -1.

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。