#coding=utf-8
import string
class Solution(object):
def firstUniqChar(self, s):
"""
:type s: str
:rtype: int
"""
k_v = {}
t = [s.find(i) for i in string.ascii_letters if s.count(i) == 1]
print t
if t == []:
return -1
else:
return min(t) #最小的index
if __name__ == '__main__':
print Solution().firstUniqChar("leetcode")
LeetCode First Unique Character in a String
最新推荐文章于 2024-03-18 09:51:10 发布
本文介绍了一个使用Python实现的方法,该方法能在给定字符串中找到第一个不重复出现的字符,并返回其索引位置。通过遍历ASCII字母表并利用字符串方法进行计数,此算法能够高效地找出目标字符。
330

被折叠的 条评论
为什么被折叠?



