First Unique Character in a String

Easy

Description

Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

Examples

Input:s = "leetcode"
Output:0
Explanation:

The first unique character is 'l' at index 0.

Input:s = "loveleetcode"
Output:2
Explanation:

The first unique character is 'v' at index 2.

Input:s = "aabb"
Output:-1
Explanation:

No unique character exists.

Constraints

  • 1 ≤ s.length ≤ 10⁵
  • s consists of only lowercase English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!