#C6536. First Non-Repeating Character
First Non-Repeating Character
First Non-Repeating Character
You are given a string s. Your task is to find the index of the first non-repeating character in s. If every character appears at least twice, output -1
.
For example, if the input string is leetcode
, the first non-repeating character is 'l'
at index 0
. If the input is loveleetcode
, the answer is 2
. In the case of aabbcc
, no such character exists so the output is -1
.
Note: The string contains only ASCII characters.
inputFormat
The input consists of a single line containing the string s.
Input Format:
s
outputFormat
Output a single integer, which is the index of the first non-repeating character in the string. If no such character exists, output -1
.
Output Format:
result## sample
leetcode
0