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