#C667. First Unique Character
First Unique Character
First Unique Character
Given a string s, find the index of the first non-repeating character in it and return its index. If it does not exist, return -1
.
The problem requires you to examine each character and determine if it appears exactly once in the string. The index is taken as the position of the character starting from 0.
The problem can be mathematically described as finding an index \( i \) such that \( s_i \) occurs exactly once in \( s \), and for all \( j \lt i \), \( s_j \) occurs more than once. If no such index exists, return \(-1\).
inputFormat
The input is provided from standard input (stdin) and contains a single string s
on one line. The string may consist of lowercase and uppercase letters.
outputFormat
Output a single integer to standard output (stdout): the index of the first non-repeating character in s
. If no such character exists, output -1
.
leetcode
0