-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1472-DesignBrowserHistory.cs
50 lines (44 loc) · 1.32 KB
/
1472-DesignBrowserHistory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//-----------------------------------------------------------------------------
// Runtime: 320ms
// Memory Usage: 47.3 MB
// Link: https://leetcode.com/submissions/detail/368946120/
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _1472_DesignBrowserHistory
{
private readonly string[] urls = new string[200];
private int current;
private int size;
public _1472_DesignBrowserHistory(string homepage)
{
current = 0;
size = 1;
urls[current] = homepage;
}
public void Visit(string url)
{
urls[++current] = url;
size = current + 1;
}
public string Back(int steps)
{
current -= steps;
if (current < 0) current = 0;
return urls[current];
}
public string Forward(int steps)
{
current += steps;
if (current >= size) current = size - 1;
return urls[current];
}
}
/**
* 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);
*/
}