diff --git a/src/hash相关/q387_字符串中的第一个唯一字符/Solution.py b/src/hash相关/q387_字符串中的第一个唯一字符/Solution.py new file mode 100644 index 0000000..6e76db3 --- /dev/null +++ b/src/hash相关/q387_字符串中的第一个唯一字符/Solution.py @@ -0,0 +1,15 @@ +class Solution: + def firstUniqChar(self, s: str) -> int: + if len(s)==0: + return -1 + res = {} + for each in s: + if each in res: + res[each]+=1 + else: + res[each] = 1 + for i,each in enumerate(s): + if res[each] ==1: + return i + return -1 +