Warm-ups · 19 of 24
First non-repeating character
Return the index of the first character that appears exactly once, or -1 if there's none.
Examples
Input s = "loveleetcode"
Output 2
'v' at index 2 is the first character that appears only once.
Input s = "aabb"
Output -1
📘 New to this? Counting with a hash map explains the idea in a few minutes.
Solved it? The same idea on LeetCode: try it there ↗