Please thumb up this one, the only C# solution so far


  • -2
    K
    public class MinStack {
        List<int> array = new List<int>();
        //int min = 35535;
        List<int> min = new List<int>();
        public void Push(int x) {
            array.Add(x);
            if(array.Count == 1)
                min.Add(x);
            else
                min.Add(x < min[min.Count - 1] ? x : min[min.Count - 1]);
        }
    
        public void Pop() {
            if(array.Count > 0)
            {
                array.RemoveAt(array.Count - 1);
                min.RemoveAt(min.Count - 1);
            }
        }
    
        public int Top() {
            return array[array.Count - 1];
        }
    
        public int GetMin() {
            return min[min.Count - 1];
        }
    }

  • 0

    "Please thumb up this one, the only C# solution so far"

    Thumbs down for begging and lying.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.