Tag: Stack

  • LeetCode: 155 Min Stack

    LeetCode: 155 Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) — Pushes element x onto the stack. pop() — Removes the element on the top of the stack. top() — Gets the top element. getMin() — Retrieves the minimum…

  • Algorithms 101: How Python Implements a Stack Behind the Scenes

    How Python Implements a Stack Behind the Scenes In Python, a stack is not a built-in data structure with a specific implementation. Instead, Python leverages lists, which are highly optimized, to function as stacks. The list data structure in Python provides all the necessary operations needed to implement a stack…

  • Algorithms 101: How to implement a stack by using two queues

    用队列实现栈 In this problem, we are required to implement a stack using two queues. The stack should support all four standard operations: push, top, pop, and empty. 在这个问题中,我们需要使用两个队列来实现一个栈。该栈应支持所有四种标准操作:push、top、pop 和 empty。 Approach The main idea behind using two queues to implement a stack is to simulate the Last In First Out…

  • Algorithms 101: Stack Implementation Using Array

    栈的数组实现 Stack Implementation Using Array A stack can be implemented using an array where the push operation adds an element to the end of the array (top of the stack), and the pop operation removes the element from the end. This implementation is simple and leverages the dynamic resizing capabilities…

  • Algorithms 101: What is a Stack

    栈是什么?What is a Stack? A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. This means that the last element added to the stack will be the first one to be removed. Stacks are used in various applications, including expression evaluation, backtracking algorithms, and the undo mechanism…

  • LeetCode: 20 Valid Parentheses

    Given a string s containing just the characters (, ), {, }, [ and ], determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Example: Input:…

  • Algorithms 101: Understanding Recursion with a Deep Dive into the Call Stack

    Algorithms 101: Understanding Recursion with a Deep Dive into the Call Stack

    Introduction In this blog post, we’ll explore the concept of recursion and how it interacts with the call stack, which is fundamental to understanding how recursive functions execute. We’ll provide practical examples in both Python and JavaScript to help solidify these concepts. By the end of this post, you should…