feat: 2025-10-29打卡

This commit is contained in:
wu xiangkai
2025-10-29 11:14:12 +08:00
parent be29138b01
commit c41c6403ff

45
155.min-stack.java Normal file
View File

@@ -0,0 +1,45 @@
/*
* @lc app=leetcode id=155 lang=java
*
* [155] Min Stack
*/
// @lc code=start
class MinStack {
private PriorityQueue<Integer> pq;
private Deque<Integer> deque;
public MinStack() {
pq = new PriorityQueue<>();
deque = new ArrayDeque<>();
}
public void push(int val) {
pq.add(val);
deque.addLast(val);
}
public void pop() {
int v = deque.removeLast();
pq.remove(v);
}
public int top() {
return deque.peekLast();
}
public int getMin() {
return pq.peek();
}
}
/**
* 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