码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode——387. 字符串中的第一个唯一字符

时间:2019-10-25 13:25:00      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:obj   nbsp   tin   sel   return   result   while   col   self   

简单题

class Solution(object):
    def firstUniqChar(self, s):
        """
        :type s: str
        :rtype: int
        """
        k=[]
        i=0
        while i<len(s):
            if s[i] in k:
                i+=1
            elif s.count(s[i])==1:
                return i
            else:
                k.append(s[i])
                i+=1
        return -1
执行用时 :176 ms, 在所有 python 提交中击败了53.69%的用户
内存消耗 :12.2 MB, 在所有 python 提交中击败了24.70%的用户
 
 
——2019.10.25

leetcode——387. 字符串中的第一个唯一字符

标签:obj   nbsp   tin   sel   return   result   while   col   self   

原文地址:https://www.cnblogs.com/taoyuxin/p/11737234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!