【leetcode❤python】 155. Min Stack
#-*- coding: UTF-8 -*-
class MinStack(object):
def __init__(self):
"""
initialize your data structure here.
"""
self.Stack=[]
self.minStack=[]
def push(self, x):
"""
:type x: int
:rtype: void
"""
self.Stack.append(x)
if len(self.minStack)==0 or x<=self.minStack[-1]:
self.minStack.append(x)
def pop(self):
"""
:rtype: void
"""
if self.Stack!=None:
if self.top()==self.minStack[-1]:
self.minStack.pop()
self.Stack.pop()
def top(self):
"""
:rtype: int
"""
if self.Stack!=None:
return self.Stack[-1]
def getMin(self):
"""
:rtype: int
"""
if self.minStack!=None:
return self.minStack[-1]
# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(x)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()
【leetcode❤python】 155. Min Stack的更多相关文章
- 【leetcode❤python】 225. Implement Stack using Queues
#-*- coding: UTF-8 -*-class Stack(object): def __init__(self): """ i ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【LeetCode】155. Min Stack 最小栈 (Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 栈同时保存当前值和最小值 辅助栈 同步栈 不同步栈 日期 题目地 ...
- 【leetcode】155 - Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- 【一天一道LeetCode】#155. Min Stack
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Design ...
- <LeetCode OJ> 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
- 【leetcode❤python】 8. String to Integer (atoi)
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...
随机推荐
- C# Extension Methods
In C#, extension methods enable you to add methods to existing class without creating a new derived ...
- Java实现插入排序
package Sort; import java.util.Arrays; public class InsertionSort { public static int[] sort(int[] l ...
- spring session 和 spring security整合
背景: 我要做的系统前面放置zuul. 使用自己公司提供的单点登录服务.后面的业务应用也是spring boot支撑的rest服务. 目标: 使用spring security管理权限包括权限.用户请 ...
- iOS,手势识别简单使用
1.iOS目前支持的手势识别(6种) 2.点按手势和慢速拖动手势简单使用 iOS目前支持的手势识别(6种) UITapGestureRecognizer(点按) UIPinchGestureRecog ...
- C# GMap下提供一个高德地图
using System; using GMap.NET.Internals; using GMap.NET.Projections; namespace GMap.NET.MapProviders ...
- 用c的数组简单的模拟了入栈
其实很简单,只要控制住输出时倒输出.且只输出一个 #include <stdio.h>#include <stdlib.h>int zhan[20];int n=-1;void ...
- Linux启用和配置Java
Firefox 在安装 Java 平台时,Java 插件文件将作为该安装的一部分包含在内.要在 Firefox 中使用 Java,您需要从该发行版中的插件文件手动创建符号链接指向 Firefox 预期 ...
- html5 webDatabase 存储中sql语句执行可嵌套使用
html5 webDatabase 存储中sql语句执行可嵌套使用,代码如下: *); data.transaction(function(tx){ tx.executeSql("creat ...
- failed to lazily initialize a collection of role:XXX, no sessi
系统 框架 springMVC+hibernate 这种情况 由于 hibernate 的 懒汉机制,和 Spring 事务机制(不确定)造成的 由于 spring 配置的时候,在service 层 ...
- PowerShell vs. PsExec for Remote Command Execution
Posted by Jianpeng Mo / January 20, 2014 Monitoring and maintaining large-scale, complex, highly dis ...