problem 3. Longest Substring Without Repeating Characters
Posted nosaferyao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了problem 3. Longest Substring Without Repeating Characters相关的知识,希望对你有一定的参考价值。
1 class Solution { 2 public: 3 int lengthOfLongestSubstring(string s) { 4 vector<int> signs(256, -1); 5 int max_length = 0; 6 int last_valid = -1; 7 for (size_t i = 0; i < s.size(); ++i){ 8 char c = s[i]; 9 int last_occ = signs[c]; 10 if (last_occ < last_valid){ 11 last_occ = last_valid; 12 } 13 if (last_occ > last_valid){ 14 last_valid = last_occ; 15 } 16 int length = i - last_occ; 17 if (length > max_length){ 18 max_length = length; 19 } 20 21 signs[c] = i; 22 } 23 if (max_length == 0){ 24 max_length = s.size(); 25 } 26 return max_length; 27 } 28 };
以上是关于problem 3. Longest Substring Without Repeating Characters的主要内容,如果未能解决你的问题,请参考以下文章
3. Longest Substring Without Repeating Characters
Leetcode 3. Longest Substring Without Repeating Characters
[LeetCode&Python] Problem 409. Longest Palindrome
3. Longest Substring Without Repeating Characters