• Leetcode练习(Python):哈希表类:第3题:给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。


    题目:
    给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
    思路:
    使用哈希表变得简单了很多,使用暴力法很容易超时。
    程序:
    class Solution:
        def lengthOfLongestSubstring(self, s: str) -> int:
            length = len(s)
            if length <= 0:
                return 0
            if length == 1:
                return 1
            head = 0
            max_length = 0
            myHashMap = {}
            for index in range(length):
                if s[index] in myHashMap and head <= myHashMap[s[index]]:
                    head = myHashMap[s[index]] + 1
                else:
                    max_length = max(max_length, index - head + 1)
                myHashMap[s[index]] = index
            return max_length
  • 相关阅读:
    myEclipse,web项目连接数据库
    jquery模拟手机短信发送
    myEclipse创建web项目及运行
    总结SUMMARY
    pthread
    NSThread线程对象
    刀哥多线程自动释放池autoreleasepool
    仿SDWebImage
    多线程基本概论multithread
    多线程异步加载图片async_pictures
  • 原文地址:https://www.cnblogs.com/zhuozige/p/12786638.html
Copyright © 2020-2023  润新知