Last active
September 27, 2016 14:01
-
-
Save beigna/8779f161e3823d577bcfeef3c48e6429 to your computer and use it in GitHub Desktop.
coso loco
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pila(object): | |
def __init__(self): | |
self._valores = [] | |
self._maximos = [] | |
def push(self, x): | |
self._valores.append(x) | |
ultimo_maximo = self._maximos.pop() | |
if x >= ultimo_maximo: | |
self._maximos.append(ultimo_maximo) | |
self._maximos.append(x) | |
else: | |
self._maximos.append(ultimo_maximo) | |
def pop(self): | |
ultimo_valor = self._valores.pop() | |
ultimo_maximo = self._maximos.pop() | |
if ultimo_valor < ultimo_maximo: | |
self._maximos.append(ultimo_maximo) | |
return ultimo_valor | |
@property | |
def max(self): | |
maximo = self._maximos.pop() | |
self._maximos.append(maximo) | |
return maximo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment