Algorithm deliberate practice -LeetCode combat 16- longest string without repeating characters (C ++)

Title: no repeat of the longest string of characters

Link to the original question: no repeat characters longest substring

I want to methods of violence, not a good feeling, to find a big brother wrote that he was about to reproduce.

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
       int st = 0;
       int len = 0;
       string str = "";
       for(int i = 0; i < s.size(); i++){
           if(str.find(s[i]) == -1) str += s[i];
           else{
               len = len > str.size() ? len : str.size();
               i = s.find_first_of(s[i], st);
               st = i + 1;
               str = "";
           }
       }
       len =  len = len > str.size() ? len : str.size();
       return len;
    }
};

Link to the original answer: no repeat characters longest substring

Digression:
a characteristic of wisdom, it is to do desperate things.
- Thoreau's "Walden"

Published 16 original articles · won praise 0 · Views 260

Guess you like

Origin blog.csdn.net/DZZ18803835618/article/details/104907036