First Unique Character in 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. The string consists of only lowercase English letters.

Examples

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

'l' is first unique.

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

All characters appear exactly twice, so there are no unique characters. Return -1.

Input:s = "programming"
Output:1
Explanation:

'r' at index 1 is the first character that appears only once in the string.

Constraints

  • 1 ≤ s.length ≤ 10⁵

Ready to solve this problem?

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