First Unique Character

Given a string s, return the position of the first character that appears exactly once in it, or -1 if every character repeats. Positions start at 0.

Constraints

  • 1 ≤ length of s ≤ 100,000
  • s has lower-case English letters only.

Example 1

Input
s = "leetcode"
Output
0
Why:

l appears only once, at position 0.

Example 2

Input
s = "loveleetcode"
Output
2
Why:

l and o repeat; v at position 2 doesn't.

Example 3

Input
s = "aabb"
Output
-1
Why:

Every letter appears twice.

Hints

    Was this a good challenge?

    Solved by
    0
    Submissions
    0
    Accepted
    –