题解 | #最长不含重复字符的子字符串#

最长不含重复字符的子字符串

http://www.nowcoder.com/practice/48d2ff79b8564c40a50fa79f9d5fa9c7

#coding:utf-8
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#

# @param s string字符串 
# @return int整型
#
class Solution:
    def lengthOfLongestSubstring(self , s ):
        # write code here
        
        d = dict()
        curLen = 0
        maxLen = 0
        for idx, item in enumerate(s):
            
            
            idxPre = d.get(item, -1)
            if idxPre == -1 or idx - idxPre > curLen:
                curLen += 1
            elif idx-idxPre < curLen:
                curLen = idx-idxPre 
            
            if curLen > maxLen:
                maxLen = curLen
#             print(idx, item, idxPre, curLen, maxLen)
            d[item] = idx
            
        return maxLen
    
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 13:05
TMD找工作本来就烦,这东西什么素质啊😡
Beeee0927:hr是超雄了,不过也是有道理的
点赞 评论 收藏
分享
06-15 20:57
已编辑
门头沟学院 Java
CARLJOSEPH...:年轻人有傲气很正常,但是建议工作前洗净傲气。 说实在的,什么奖学金什么奖项的都很一般。尊重你的老师,在有时间的时候去上课,真遇到走不开的事,请态度端正地向你的老师说明情况,请求请假。我相信任何一个有师德的老师都会允许的(我的老师就是这样)。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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