Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 데이터
- sort
- db
- 티스토리챌린지
- mysql
- Mesh
- 코테
- 컴퓨터사이언스
- DS
- CNN
- code
- GNN
- SQL
- Data_Structure
- coding
- meshgraphnet
- Python
- 데이터베이스
- Leet Code
- 오블완
- LeetCode
- CS
- 자료구조
- 컴퓨터공학
- 대학생
- 개발자
- 데베
- 코딩테스트
- Database
- adaptive remeshing
Archives
- Today
- Total
sy1214ei 님의 블로그
[Leet Code] 3. Longest Substring Without Repeating Characters 본문
level : Medium
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
"""
슬라이딩 윈도우
- 부분 문자열에 중복 문자 X: end += 1
- 부분 문자열에 중복 문자 O: start += 1
"""
max_len = 0
start, end = 0, 0
chars = set()
while end < len(s):
if s[end] in chars: # 부분 문자열에 중복 문자 O
chars.remove(s[start])
start += 1
else: # 부분 문자열에 중복 문자 X
chars.add(s[end])
max_len = max(end-start+1, max_len)
end += 1
return max_len

'[Coding]' 카테고리의 다른 글
| [Leet Code] 500. Keyboard Row - Python (0) | 2024.12.23 |
|---|---|
| [Leet Code] 349. Intersection of Two Arrays - Python (0) | 2024.12.16 |
| [Leet Code] 41. First Missing Positive - Python (1) | 2024.12.16 |
| [Leet Code] 409. Longest Palindrome - Python (2) | 2024.12.04 |
| [Leet Code] 1. Two Sum - Python (0) | 2024.12.03 |