Leetcode 1472. 设计浏览器历史记录 (数组模拟)
作者:互联网
class BrowserHistory {
private:
vector<string> urls;
int cur;
public:
BrowserHistory(string homepage) {
cur = 0;
urls.push_back(homepage);
}
void visit(string url) {
urls.erase(urls.begin() + cur + 1, urls.end());
urls.push_back(url);
cur++;
}
string back(int steps) {
cur = max(0, cur - steps);
return urls[cur];
}
string forward(int steps) {
cur = min(cur + steps, (int)urls.size() - 1);
return urls[cur];
}
};
/**
* 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);
*/
标签:浏览器,string,int,BrowserHistory,1472,steps,urls,Leetcode,cur 来源: https://blog.csdn.net/wwxy1995/article/details/121384663