题目描述
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。
样例
s = “leetcode”
返回 0.
s = “loveleetcode”,
返回 2.
python解法
class Solution:
def firstUniqChar(self, s: str) -> int:
from collections import Counter
dic = Counter(s)
for i in dic:
if dic[i] == 1:
return s.index(i)
return -1
执行用时 : 76ms
内存消耗 : 13.8MB
题后反思:无
C语言解法
先不写了,以后再补
执行用时 : ms
内存消耗 : MB
题后反思:
文中都是我个人的理解,如有错误的地方欢迎下方评论告诉我,我及时更正,大家共同进步