| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 스탭퍼
- Problem Solving
- 읽기
- 3줄정리
- 월간
- leetcode
- Writing
- 뭐든
- 영어원서읽기
- 잡생각
- 프로젝트
- 30분
- 개발자
- 쓰릴오브파이트
- FIT XR
- 매일
- 파비최
- realclass
- 만화도
- 화상영어
- Daily Challenge
- 리얼 클래스
- 10분
- English
- 링피트
- 운동
- 영어공부
- 괜찮음
- 사이드
- 미드시청
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