zoukankan      html  css  js  c++  java
  • 3. Longest Substring Without Repeating Characters

    题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/

     自我感觉难度/真实难度:             写题时间时长:

     题意:

     分析:

     自己的代码:

    class Solution(object):
        def lengthOfLongestSubstring(self, s):
            """
            :type s: str
            :rtype: int
            """
            start=maxlen=0
            sueedChar={}
            for i in range(len(s)):
                if s[i] in sueedChar and start<=sueedChar[s[i]]:
                    start=sueedChar[s[i]]+1
                else:
                    maxlen=max(maxlen,i-start+1)
                sueedChar[s[i]]=i
            return maxlen
    start<=sueedChar[s[i]],主要是针对出现两个字母重复但是临近的时候。

    代码效率/结果:

    Runtime: 48 ms, faster than 89.58% of Python online submissions forLongest Substring Without Repeating Characters.
    Memory Usage: 12.7 MB, less than 6.10% of Python online submissions forLongest Substring Without Repeating Characters.

     优秀代码:

    代码效率/结果:

     自己优化后的代码:

     反思改进策略:

  • 相关阅读:
    php 解析xml
    php
    php 设置自动加载某个页面
    Mac
    mysql
    Git
    C#
    C# 正则表达式
    C# ASCII码排序
    (转)datagridview 自定义列三步走
  • 原文地址:https://www.cnblogs.com/captain-dl/p/10836999.html
Copyright © 2011-2022 走看看