Skip to content

Instantly share code, notes, and snippets.

@beigna
Last active September 27, 2016 14:01
Show Gist options
  • Save beigna/8779f161e3823d577bcfeef3c48e6429 to your computer and use it in GitHub Desktop.
Save beigna/8779f161e3823d577bcfeef3c48e6429 to your computer and use it in GitHub Desktop.
coso loco
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