일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로젝트
- FIT XR
- Daily Challenge
- realclass
- 리얼 클래스
- leetcode
- 사이드
- 파비최
- 10분
- 운동
- English
- 링피트
- 잡생각
- Problem Solving
- 화상영어
- 미드시청
- 영어공부
- 매일
- 괜찮음
- 3줄정리
- 개발자
- 30분
- Writing
- 영어원서읽기
- 뭐든
- 쓰릴오브파이트
- 만화도
- 스탭퍼
- 읽기
- 월간
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/longest-substring-without-repeating-characters/
Longest Substring Without Repeating Characters - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
어제에 이어서 오늘도 Two Pointer 문제.
지난주 스터디에서 작성했던 소스 참고해서 내 힘으로 품!! 오예~~
(5번 WA 뜬 건 안 비밀.....)
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
ar = [0] * 128
l = len(s)
left, right = 0, 0
res = 0
if l == 0:
return 0
if l == 1:
return 1
while left <= right:
if ar[ord(s[right])] == 0:
ar[ord(s[right])] += 1
right += 1
elif ar[ord(s[right])] > 0:
ar[ord(s[left])] -= 1
left += 1
res = max(res, right-left)
if right == l:
break
return res
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.06.12 |
---|---|
Today's Challenge (0) | 2022.06.11 |
Today's Challenge (0) | 2022.06.09 |
Today's Challenge (0) | 2022.06.08 |
Today's Challenge (0) | 2022.06.07 |
Comments