My LeetCode grinding. Trying to do a problem a day.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122
  1. class Solution:
  2. def firstUniqChar(self, s):
  3. seen = dict()
  4. for x in range(len(s)):
  5. if s[x] in seen:
  6. seen[s[x]][0] += 1
  7. else:
  8. seen[s[x]] = [1, x]
  9. result = None
  10. for key, val in seen.items():
  11. if val[0] == 1 and (result is None or val[1] < result):
  12. result = val[1]
  13. if result is None:
  14. return -1
  15. return result
  16. s = Solution()
  17. print("Expected: 0")
  18. print("Got:", s.firstUniqChar("leetcode"))