일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 운동
- Problem Solving
- 스탭퍼
- realclass
- 매일
- 영어공부
- 사이드
- 읽기
- 화상영어
- 뭐든
- 만화도
- 링피트
- English
- 잡생각
- Daily Challenge
- 괜찮음
- 30분
- leetcode
- Writing
- 쓰릴오브파이트
- 파비최
- FIT XR
- 개발자
- 미드시청
- 10분
- 영어원서읽기
- 프로젝트
- 월간
- 3줄정리
- 리얼 클래스
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.18 Today's Challenge 본문
https://leetcode.com/problems/design-browser-history/
Design Browser History - LeetCode
Can you solve this real interview question? Design Browser History - You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps. Implem
leetcode.com
링크드리스트를 이용한 풀이
class Node:
def __init__(self, url: str):
self.prev = None
self.next = None
self.url = url
class BrowserHistory:
def __init__(self, homepage: str):
self.curr = Node(homepage)
def visit(self, url: str) -> None:
self.curr.next = Node(url)
self.curr.next.prev = self.curr
self.curr = self.curr.next
def back(self, steps: int) -> str:
while self.curr.prev and steps > 0:
self.curr = self.curr.prev
steps -= 1
return self.curr.url
def forward(self, steps: int) -> str:
while self.curr.next and steps > 0:
self.curr = self.curr.next
steps -= 1
return self.curr.url
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.20 Today's Challenge (0) | 2023.03.20 |
---|---|
2023.03.19 Today's Challenge (0) | 2023.03.19 |
2023.03.17 Today's Challenge (0) | 2023.03.17 |
2023.03.16 Today's Challenge (0) | 2023.03.16 |
2023.03.15 Today's Challenge (0) | 2023.03.15 |
Comments