stack
and values
, and a counter cnt
.push(x)
, insert the element with the current cnt
into both stack
and values
, then increment cnt
.top()
, return the last element's value from stack
.peekMax()
, return the last element's value from values
.pop()
, remove the last element from stack
, find and remove the same element in values
, and return its value.popMax()
, remove the last element from values
, find and remove the same element in stack
, and return its value.