标签:substr 时间 mat longest 空间复杂度 tar tin ict character
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)
标签:substr 时间 mat longest 空间复杂度 tar tin ict character
原文地址:https://www.cnblogs.com/eniac-inner/p/12468864.html