-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path155.min-stack.cs
More file actions
45 lines (35 loc) · 795 Bytes
/
155.min-stack.cs
File metadata and controls
45 lines (35 loc) · 795 Bytes
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
/*
* @lc app=leetcode id=155 lang=csharp
*
* [155] Min Stack
*/
// @lc code=start
public class MinStack {
private Node _root;
record Node(int val, int min, Node prev) {}
public MinStack() {
_root = new(int.MaxValue,int.MaxValue,null);
}
public void Push(int val) {
Node n = new(val, Math.Min(val, _root.min), _root);
_root = n;
}
public void Pop() {
_root = _root.prev;
}
public int Top() {
return _root.val;
}
public int GetMin() {
return _root.min;
}
}
/**
* Your MinStack object will be instantiated and called as such:
* MinStack obj = new MinStack();
* obj.Push(val);
* obj.Pop();
* int param_3 = obj.Top();
* int param_4 = obj.GetMin();
*/
// @lc code=end