Title Description:
Given a string, find the first non-repeating character in it and return it ' s index. If it doesn ' t exist, return-1.
Examples:
s = "Leetcode" return 0.s = "Loveleetcode", return 2.
Note:you may assume the string contain only lowercase letters.
My answer:
Main ideas:
First, turn the string into a list of letters, then iterate through the list letters to create a counting dictionary and an index dictionary, and then iterate through the alphabetical list to find the first occurrence of the index of 1 letters.
Error point:
1 Get Count Dictionary Uni and Index Dictionary ind, directly in Uni look for a value of 1 letters, so the reason for the error is that after the counting dictionary, the alphabetical order has changed, the resulting letter is not the first occurrence
2 ignore the non-existent situation, for the absence of the situation, that is, all counts are greater than 1, the method used here is a count greater than 1, if the last number equal to the length of the list indicates that there is no
3 is always written as a logical operation =, should be a double equals = =
Knowledge Points:
For index,t in enumerate (list) to traverse list values and indexes at the same time
For k,v in Uni.items () to traverse the key and value of the dictionary uni at the same time
Leetcode notes First Unique Character in a String