1. 程式人生 > >#3 Longest substring without repeating characters

#3 Longest substring without repeating characters

  1. Sliding window

  2. Hashset

  3. Loop through every element inside the string. If the current char is not inside the hashset, push the char into the hashset and update the longest value. If the current char is already inside the hashset, change the left boundary of the sliding window until the current char is not inside the hashset.

  4. Return the longest value.

  5. Time complexity: O(n). Space complexity: O(the size of the hashset)