#K42827. First Unique Character
First Unique Character
First Unique Character
Given a string s
consisting of only lowercase English letters, find the index of the first non-repeating character in s
. If no such character exists, output \(-1\).
For example, if s = "leetcode"
, the answer is 0
, because 'l' is the first unique character. In contrast, for s = "aabb"
, all characters repeat, so the answer is -1
.
Note: The string input may be empty. When working with inputs, read a single line from standard input and output the result to standard output.
inputFormat
The input consists of a single line containing the string s
with only lowercase English letters. The string may be empty.
outputFormat
Output a single integer representing the index of the first non-repeating character in s
. If no such character exists, output -1
.
leetcode
0