First Unique Character
Sometimes you need to find the first character that appears only once in a string, such as the first unique letter in a code, name, or message. Given a string s, return the index of the first non-repeating character. If every character repeats, return -1.
Примеры
Ввод
"leetcode"Вывод
0Ввод
"loveleetcode"Вывод
2Ввод
"aabb"Вывод
-1Нужно реализовать
def first_uniq_char(s: str) -> int:
Теги
stringshashmap
Pieslēdzies, lai redzētu iesniegumu vēsturi
PieslēgtiesPieslēdzies, lai izmantotu AI mentoru
PieslēgtiesVisible tests
1
Input
"leetcode"Expected
02
Input
"loveleetcode"Expected
23
Input
"aabb"Expected
-14
Input
"z"Expected
05
Input
"aadadaad"Expected
-16
Input
" "Expected
-1Focus radio
Paused · SomaFM · Fluid