First Unique Character in a String leetcode| first unique character in a string python | May Day 5

preview_player
Показать описание
Please like the video, this really motivates us to make more such videos and helps us to grow. thecodingworld is a community which is formed to help fellow student and professionals looking to crack the “coding interviews”.

We love solving and sharing problems which are frequently asked in technical interviews and voted by community at various websites.

✅ For more and upcoming updates join our community

#leetcode #python
Рекомендации по теме
Комментарии
Автор

Hi,
How about using collections.counter for identifying element with count 1 and enumerate to find the index of the letter which is equal to 1.


dict1=dict(Counter(s))
dict2={x[1]:x[0] for x in list(enumerate(s))}
for x in s:
if dict1[x]==1:
return dict2[x]

return -1

chaitanyareddy
welcome to shbcf.ru