
Problem: 1472. Design Browser History 设计浏览器历史记录使用了指针和列表的呢指针永远指向当前访问的链接visit时若if(ind1 (int)tr.size()) tr.resize(ind 1);需要resize列表的容量back和forward都需要拿到最小值防止越界的Codeclass BrowserHistory { public: vectorstring tr; int ind-1; BrowserHistory(string homepage) { tr.push_back(homepage); ind; } void visit(string url) { if(ind1 (int)tr.size()) tr.resize(ind 1); tr.push_back(url); ind; } string back(int steps) { steps min(steps, ind); ind ind - steps; return tr[ind]; } string forward(int steps) { steps min(steps, (int)tr.size() - ind - 1); ind ind steps; return tr[ind]; } }; /** * Your BrowserHistory object will be instantiated and called as such: * BrowserHistory* obj new BrowserHistory(homepage); * obj-visit(url); * string param_2 obj-back(steps); * string param_3 obj-forward(steps); */