← 返回 meta 的题目列表Unique Characters
类型:online_judge
Problem: Unique Characters
Given an ASCII string s (may contain spaces and punctuation), find the first “unique character”.
Unique character: a character that appears exactly once in the string.
Output:
The 0-based index of the first unique character in s.
If no unique character exists, output -1.
Input
One line containing the string s.
Output
A single integer: the 0-based index of the first unique character, or -1 if none exists.
Constraints
0 <= len(s) <= 2 * 10^5
ASCII charset (0~127)
Target time complexity: O(n)
Test cases
Example
Input
leetcode
Output
0