3. Longest Substring Without Repeating Characters Leetcode: 3. Longest Substring Without Repeating Characters Problem Statement Given a string s, find the length of the longest substring without duplicate characters. Solutions Hash 1 2 3 4 5 6 7 8 9 10 11 12int lengthOfLongestSubstring(string s) { vector<int> table(256, -1); int l = 0, ans = 0; for (int i = 0; i < s.size(); i++) { char c = s[i]; l = max(table[c] + 1, l); ans = max(i - l + 1, ans); table[c] = i; } return ans; } Tags Leetcode Medium Hash