C++ | Leetcode C++题解之第155题最小栈

题目:

题解:

class MinStack {
    stack<int> x_stack;
    stack<int> min_stack;
public:
    MinStack() {
        min_stack.push(INT_MAX);
    }
    
    void push(int x) {
        x_stack.push(x);
        min_stack.push(min(min_stack.top(), x));
    }
    
    void pop() {
        x_stack.pop();
        min_stack.pop();
    }
    
    int top() {
        return x_stack.top();
    }
    
    int getMin() {
        return min_stack.top();
    }
};

相关推荐

  1. 【LeetCode热100】155.

    2024-06-17 14:04:05       41 阅读
  2. 155.

    2024-06-17 14:04:05       55 阅读
  3. 【力扣100】【好155.

    2024-06-17 14:04:05       64 阅读
  4. LeetCode-热100:155.

    2024-06-17 14:04:05       41 阅读
  5. leetcode热HOT 155.

    2024-06-17 14:04:05       33 阅读
  6. LeetCode练习与总结:--155

    2024-06-17 14:04:05       21 阅读
  7. LeetCode 155

    2024-06-17 14:04:05       55 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-17 14:04:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-17 14:04:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-17 14:04:05       87 阅读
  4. Python语言-面向对象

    2024-06-17 14:04:05       96 阅读

热门阅读

  1. VB.net调用VC DLL(二)

    2024-06-17 14:04:05       31 阅读
  2. 教学资源共享平台的设计

    2024-06-17 14:04:05       34 阅读
  3. 【C语言】进程间通信之管道pipe

    2024-06-17 14:04:05       35 阅读
  4. UVa1516/LA5906 Smoking gun

    2024-06-17 14:04:05       34 阅读
  5. tf-idf算法

    2024-06-17 14:04:05       28 阅读
  6. 大数据开发语言Scala入门 ,如何入门?

    2024-06-17 14:04:05       37 阅读