Find the 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 letter 'l' is the first unique character and appears at index 0.
Example 2
Input
[ "loveleetcode" ]
Output
2
Explanation. The letter 'v' is the first unique character and appears at index 2.
Example 3
Input
[ "aabb" ]
Output
-1
Explanation. There are no unique characters in the string.
Follow-up: Can you solve this problem using O(n) time complexity and O(1) space complexity?
Constraints:
The input string will only contain lowercase English letters.
- Views
- 3