## [1472\. 設計瀏覽器歷史記錄](https://leetcode-cn.com/problems/design-browser-history/)
#### 思路
周賽看到這道題都樂了,感覺對不起他的5分這個分數。感覺主要考察閱讀理解。那首先就**閱讀理解**一下
* 記錄瀏覽器的訪問記錄,可以前進可以后退
* 后退返回之前的頁面
* 前進訪問返回前的頁面
* 假如在當前頁跳到一個新的頁面,那之前的前進頁就都作廢。就是這時候就前進不了了
我們只要使用兩個變量:
* **隊列** 用于存放記錄
* **當前頁面索引** 用于存放當前訪問的頁面是哪個
* 接著處理一下*返回之后,轉跳到新頁面需要更新隊列的情況*
* 考慮邊界情況
AC!
#### 代碼
python
```
class BrowserHistory(object):
def __init__(self, homepage):
"""
:type homepage: str
"""
self.queue = []
self.queue.append(homepage)
self.curindex = 0
def visit(self, url):
"""
:type url: str
:rtype: None
"""
if self.curindex < (len(self.queue) - 1):
self.queue = self.queue[:self.curindex + 1][::]
self.queue.append(url)
self.curindex = len(self.queue) - 1
def back(self, steps):
"""
:type steps: int
:rtype: str
"""
if self.curindex - steps < 0:
self.curindex = 0
return self.queue[0]
else:
self.curindex -= steps
return self.queue[self.curindex]
def forward(self, steps):
"""
:type steps: int
:rtype: str
"""
if self.curindex + steps > len(self.queue) - 1:
self.curindex = len(self.queue) - 1
return self.queue[(len(self.queue) - 1)]
else:
self.curindex += steps
return self.queue[self.curindex]
```
- 目錄
- excel-sheet-column-number
- divide-two-integers
- house-robber
- fraction-to-recurring-decimal
- profile
- kids-with-the-greatest-number-of-candies
- qiu-12n-lcof
- new-21-game
- product-of-array-except-self
- minimum-depth-of-binary-tree
- univalued-binary-tree
- shun-shi-zhen-da-yin-ju-zhen-lcof
- permutations
- satisfiability-of-equality-equations
- word-ladder-ii
- ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof
- palindrome-number
- network-delay-time
- daily-temperatures
- longest-common-prefix
- sum-of-mutated-array-closest-to-target
- 周賽專題
- make-two-arrays-equal-by-reversing-sub-arrays
- check-if-a-string-contains-all-binary-codes-of-size-k
- course-schedule-iv
- cherry-pickup-ii
- maximum-product-of-two-elements-in-an-array
- maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts
- reorder-routes-to-make-all-paths-lead-to-the-city-zero
- probability-of-a-two-boxes-having-the-same-number-of-distinct-balls
- shuffle-the-array
- the-k-strongest-values-in-an-array
- design-browser-history
- paint-house-iii
- final-prices-with-a-special-discount-in-a-shop