Youwang Deng

I'm a software developer, familiar with C#, Java, JavaScript, focus on full stack development.

Leetcode Stack & Queue Note

08 Jul 2019 » Leetcode-Stack, Leetcode-Queue

Stack - FILO data structure

  • could be implemented with Array or LinkedList
  • use helper stack to assist getMin, getMax, reverse, swap or replace element
  • use stack to store the index of the element instead of the element itself
  • use queue to implement stack(tmp queue & body queue, offer and poll, swap reference)

Queue - FILO data structure

  • could be implemented with Array or LinkedList
  • store index
  • use stack to implement queue, two stack swap reference, push O(n), pop O(1), peek O(1)