LeetCode 155. Design Min Stack, Max Stack, Median Stack

relevant problems:

Problem Clarification

Stack is a fundamental data structure for LIFO (Last In First Out), which basically supports:

Now design an advanced stack that also supports:

* Here in MedianStack, the definition for median is a little different from its mathematical definition: with N elements, the median value is defined to be the $N/2$-th smallest element if N is even, or $(N+1)/2$-th if N is odd.

Analysis

Code

* Code here have minor differences in regard to methods implemented (popM may not be required), method names (“peek” and “get”), and return types (whether pop returns None), in order to be applied directly on LeetCode.