力扣1472.设计浏览器历史记录

力扣1472.设计浏览器历史记录

  • 用双指针记录历史记录

    • 以及栈顶高度
    • 移动时会直接把之前的记录消掉
  •   class BrowserHistory {
          int pos=-1;
          int top=0;
          string history[5010];
      public:
          BrowserHistory(string homepage) {
              visit(homepage);
          }
          
          void visit(string url) {
              pos ++;
              top = pos;
              history[top] = url;
          }
          
          string back(int steps) {
              if(steps >pos)
                  steps = pos;
              pos -= steps;
              return history[pos];
          }
          
          string forward(int steps) {
              steps = min(steps,top - pos);
              pos += steps;
              return history[pos];
          }
      };
    

相关推荐

  1. 1472.设计浏览器历史记录

    2024-07-10 19:24:03       12 阅读
  2. 记录 4.8

    2024-07-10 19:24:03       16 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 19:24:03       5 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 19:24:03       5 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 19:24:03       4 阅读
  4. Python语言-面向对象

    2024-07-10 19:24:03       7 阅读

热门阅读

  1. ArcGIS Pro SDK (八)地理数据库 3 数据

    2024-07-10 19:24:03       11 阅读
  2. C语言 找出一个二维数组中的鞍点

    2024-07-10 19:24:03       10 阅读
  3. [目标检测]labelme标注数据转yoloV8需要的.txt格式

    2024-07-10 19:24:03       10 阅读
  4. ES6 之 Promise 构造函数知识点总结 (四)

    2024-07-10 19:24:03       12 阅读
  5. 软件工程需求之:业务需求与用户需求

    2024-07-10 19:24:03       6 阅读