First Unique Character in a String

Easy

Find the first non-repeating character in s and return its index.

If every character repeats, return -1.

Example 1

firstUniqChar()
Input
s = "leetcode"
Output
0

Why

`l` is the first character that appears once.

Example 2

firstUniqChar()
Input
s = "loveleetcode"
Output
2
Constraints
1 <= s.length <= 10^5
`s` consists of lowercase English letters.

Topics

StringsHash Table

Implement firstUniqChar in the editor and return the answer — printing it is never graded.