解题思路:

没什么解题思路,烦死了这种题

提交代码:

class MinStack {

	/** initialize your data structure here. */
	Stack<Integer> st = new Stack<Integer>();
	int min = Integer.MAX_VALUE;

	public MinStack() {

	}
	public void push(int x) {
		if (x <= min) {
			st.push(min);
			min = x;
		}
		st.push(x);
	}

	public void pop() {
		if (st.pop() == min)
			min = st.pop();
	}

	public int top() {
		return st.peek();
	}

	public int getMin() {
		return min;
	}
}

运行结果:

【leetcode】155(Easy). Min Stack

相关文章:

  • 2021-07-11
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2022-02-04
  • 2021-09-23
  • 2021-12-08
  • 2021-09-29
  • 2021-12-20
  • 2021-10-26
  • 2021-07-09
相关资源
相似解决方案