zoukankan      html  css  js  c++  java
  • Leetcode:Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters.

    Example 1:

    Input: "abcabcbb"
    Output: 3 
    Explanation: The answer is "abc", with the length of 3. 
    

    Example 2:

    Input: "bbbbb"
    Output: 1
    Explanation: The answer is "b", with the length of 1.
    

    Example 3:

    Input: "pwwkew"
    Output: 3
    Explanation: The answer is "wke", with the length of 3. 
                 Note that the answer must be a substring, "pwke" is a subsequence and not a substring.


    方法一,暴力穷举法,不多说了。

    方法二,使用HashSet维护一个字符串中的滑动窗口,在最多O(2n)的时间内便利完。

    方法三,使用HashMap保存字符对应下标, 使得左边窗口边界可以快速滑动。



    代码地址:https://github.com/chy996633/leetcode/blob/master/src/LongestSubstringWithoutRepeatingCharacters.java




  • 相关阅读:
    垃圾收集器
    垃圾收集算法
    JVM内存模型
    工厂方法模式
    类加载机制
    六大设计原则
    单例模式
    HFish开源蜜罐搭建
    利用metasploit复现永恒之蓝
    零信任网络初识
  • 原文地址:https://www.cnblogs.com/andrew-chen/p/10155663.html
Copyright © 2011-2022 走看看