Skip to main content
107, Binary Tree Level Order Traversal II

I Problem

Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).

Example 1

Input: root = [3, 9, 20, null, null, 15, 7]
Output: [[15, 7], [9, 20], [3]]


MikeAbout 2 minbinary treemediumqueuebinary treebreadth first search
102, Binary Tree Level Order Traversal

I Problem

Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

Example 1

Input: [3, 9, 20, null, null, 15, 7]
Output: [[3], [9, 20], [15, 7]]

Example 2
Input: root = [1]
Output: [[1]]


MikeAbout 2 minbinary treemediumqueuebinary treebreadth first search
239, Sliding Window Maximum

I Problem

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.


MikeAbout 3 minstack/queuehardarrayqueuesliding windowheadmonotonic queue
225, Implement Stack using Queues

I Problem

Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty).

Implement the MyStack class:

  • void push(int x) Pushes element x to the top of the stack.
  • int pop() Removes the element on the top of the stack and returns it.
  • int top() Returns the element on the top of the stack.
  • boolean empty() Returns true if the stack is empty, false otherwise.

MikeAbout 2 minstack/queueeasystackqueuedesign
232, Implement Queue using Stacks

I Problem

Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).

Implement the MyQueue class:

  • void push(int x) Pushes element x to the back of the queue.
  • int pop() Removes the element from the front of the queue and returns it.
  • int peek() Returns the element at the front of the queue.
  • boolean empty() Returns true if the queue is empty, false otherwise.

MikeAbout 2 minstack/queueeasystackqueuedesign
Stack/Queue

Stack/Queue

Stack

In computer science, a stack is an abstract data type that serves as a collection of elements with two main operations:

  • Push, which adds an element to the collection, and
  • Pop, which removes the most recently added element.


MikeAbout 2 minleetcodestackqueue