<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## [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] ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看