Đề bài
Xem bản dịchReturn 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.
Ràng buộc
0 ≤ length ≤ 100,000
Ví dụ
Ví dụ 1
Đầu vào:
text = "swiss"
Kết quả mong đợi:
expected = 1
Đầu vào:
std::string text = "swiss";
Kết quả mong đợi:
long long expected = 1;
Đầu vào:
string text = "swiss";
Kết quả mong đợi:
long expected = 1;
Giải thích
s repeats, w appears once at index 1.
Ví dụ 2
Đầu vào:
text = "aabb"
Kết quả mong đợi:
expected = -1
Đầu vào:
std::string text = "aabb";
Kết quả mong đợi:
long long expected = -1;
Đầu vào:
string text = "aabb";
Kết quả mong đợi:
long expected = -1;
Giải thích
Every character repeats: -1.
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.