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




  • 相关阅读:
    HDU 2544 (Djikstra)
    HDU 1237(表达式求值)
    HDU1690 (Floyd)
    《大道至简》读后感
    第6周总结
    第8周总结
    第7周总结
    第四周总结
    第5周总结
    java程序
  • 原文地址:https://www.cnblogs.com/andrew-chen/p/10155663.html
Copyright © 2011-2022 走看看