zoukankan      html  css  js  c++  java
  • 【剑指Offer】20包含min函数的栈

    题目描述

    定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1))。

    时间限制:1秒;空间限制:32768K;本题知识点:栈

    解题思路

    # -*- coding:utf-8 -*-
    class Solution:
        def __init__(self):
            self.stack = []
        def push(self, node):
            # write code here
            self.stack.append(node)
        def pop(self):
            # write code here
            return self.stack.pop()
        def top(self):
            # write code here
            return len(self.stack)
        def min(self):
            # write code here
            return min(self.stack)
  • 相关阅读:
    RegExp
    svn操作
    前端跨域请求
    UML
    excel 常用设置
    python中 cmp
    python global nonlocal
    python常见异常提示
    table边框和td的width失效
    display_css
  • 原文地址:https://www.cnblogs.com/yucen/p/9912040.html
Copyright © 2011-2022 走看看