We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 12facde commit c163adfCopy full SHA for c163adf
C++/design-browser-history.cpp
@@ -0,0 +1,33 @@
1
+// Time: ctor : O(1)
2
+// visit : O(1)
3
+// back : O(1)
4
+// foward: O(1)
5
+// Space: O(n)
6
+
7
+class BrowserHistory {
8
+public:
9
+ BrowserHistory(string homepage)
10
+ : history_(1, homepage)
11
+ , curr_{0} {
12
13
+ }
14
15
+ void visit(string url) {
16
+ history_.resize(++curr_);
17
+ history_.emplace_back(url);
18
19
20
+ string back(int steps) {
21
+ curr_ = max(curr_ - steps, 0);
22
+ return history_[curr_];
23
24
25
+ string forward(int steps) {
26
+ curr_ = min(curr_ + steps, int(history_.size()) - 1);
27
28
29
30
+private:
31
+ vector<string> history_;
32
+ int curr_;
33
+};
0 commit comments