leetcode 3. Longest Substring Without Repeating Characters (java)

Posted eniac-inner

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 3. Longest Substring Without Repeating Characters (java)相关的知识,希望对你有一定的参考价值。

class Solution {
    public int lengthOfLongestSubstring(String s) {
        int[] dict = new int[256];
        Arrays.fill(dict, -1);
        int maxLen = 0, start = -1;
        for (int i = 0; i < s.length(); i++) {
            if (dict[s.charAt(i)] > start) {
                start = dict[s.charAt(i)];
            }
            dict[s.charAt(i)] = i;
            maxLen = Math.max(maxLen, i - start);
        }
        return maxLen;
    }
}

//时间复杂度: O(n)
//空间复杂度: O(1)

  

以上是关于leetcode 3. Longest Substring Without Repeating Characters (java)的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode 3. Longest Substring Without Repeating Characters

LeetCode 3. Longest Substring Without Repeating

3. 没有重复字母的最长子串 [leetcode 3: Longest Substring Without Repeating Characters]

3. 没有重复字母的最长子串 [leetcode 3: Longest Substring Without Repeating Characters]

leetcode longest consecutive sequence

leetcode 3. Longest Substring Without Repeating Characters (Python版)