First Unique Character
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write firstUnique(text): return the index of the first character in text that appears exactly once, or -1 if there isn't one, including for empty text. Upper and lower case count as different characters. For example, firstUnique("loveleetcode") is 2, the "v", and firstUnique("aabb") is -1. The checks include text about 150,000 characters long, so searching the whole text again for every character is too slow.
Your code must pass
- Finds the first character that appears once
- Returns -1 when every character repeats
- Treats upper and lower case as different
- Is fast enough for 150,000 characters