Blind 75 | Longest Substring Without Repeating Characters (Sliding Window 2 / 4)
https://leetcode.com/problems/longest-substring-without-repeating-characters/
Longest Substring Without Repeating Characters - LeetCode
Can you solve this real interview question? Longest Substring Without Repeating Characters - Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "
leetcode.com
Longest Substring Without Repeating Characters - 반복 문자 없는 제일 긴 문자열
Given a string s, find the length of the longest substring without repeating characters.
문자열 s가 주어졌을 때, 반복되는 문자가 없는 가장 긴 하위 문자열을 찾아라.
풀이
Set을 이용해서 반복되는 문자를 찾으면 제거한다.
left, right을 0, 0에서 시작해서 right을 한 칸씩 늘려가며
s[right]을 Set에 추가하며 길이를 계산한다.
만약 금방 넣은 문자가 Set에 이미 있었다면
반복되는 첫 문자가 있는 지점까지 모든 문자를 지우며 left를 한 칸씩 늘려간다.
코드
자주 나오는 패턴 중의 하나로 프로그래머스의 보석 쇼핑이라는 문제가 이 패턴을 살짝 응용해서 사용한다.
https://school.programmers.co.kr/learn/courses/30/lessons/67258