[LeetCode]387. First Unique Character in a String
题目
Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.
Examples:
1 | s = "leetcode" |
Note: You may assume the string contain only lowercase letters.
难度
Easy
方法
先用一个dict统计每个单词出现的次数,然后从头开始检查s
的字符,如果字符出现次数为1
,则返回该字符的位置; 如果所有字符出现字数都不为1
,则返回-1
python代码
1 | class Solution(object): |