First Unique Character
easySave
CountingHash TableString
Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1.
Example 1
Input
[ "leetcode" ]
Output
0
Explanation. The first unique character is 'l', which is at index 0.
Example 2
Input
[ "loveleetcode" ]
Output
2
Explanation. The first unique character is 'v', which is at index 2.
Example 3
Input
[ "aabb" ]
Output
-1
Explanation. There is no unique character in the string, so we return -1.
Follow-up: Can your solution handle strings containing characters from different character sets (e.g., Unicode)?
Constraints:
- The input string will not be empty.\n- You may assume the string contains only lowercase letters.
- Views
- 3