From a7da4d82025a9a51b06928e88dd64b0c0e528390 Mon Sep 17 00:00:00 2001 From: buaazhangqi <2445657635@qq.com> Date: Sun, 16 Aug 2020 23:04:41 +0800 Subject: [PATCH] Create Solution.py --- .../Solution.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/hash相关/q387_字符串中的第一个唯一字符/Solution.py 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 +