python

第一个只出现一次的字符

http://www.nowcoder.com/questionTerminal/1c82e8cf713b4bbeb2a5b31cf5b0417c

我是这么写的,运行时间虽然通过了,但是好像时间挺长的。。。

-*- coding:utf-8 -*-
class Solution:
    def FirstNotRepeatingChar(self, s):
        # write code here
        if not s:
            return -1
        ls = []
        re = []
        for i in s:
            if i not in ls:
               #以ls为对照,修改re里的字符
                ls.append(i)
                re.append(i)
               #重复的就删减re中的
            elif i in re:
                re.remove(i)
        return s.index(re[0])
全部评论

相关推荐

专业码bug百年:整个宇宙为你而闪烁
点赞 评论 收藏
分享
2025-12-15 12:50
河北工程大学
sta666:我也是这个国际商业化的,三天,一天一面,就通过了,不过我是后端实习生,好好面感觉能过。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务