NeetCode Comprehensive Algorithm Bank & Offline Handbook
Synchronized bilingual toggle with dual NeetCode & LeetCode problem numbering and direct links. Features step-by-step logic, benchmark Python3 code, complexity analysis, interview pitfalls, and standalone offline exports.
Split Linked List in Parts (分隔链表)
Given the head of a singly linked list and an integer k, split the list into k consecutive parts. The parts must have sizes differ...
LRU Cache (LRU 缓存)
Design a Least Recently Used (LRU) cache with a fixed capacity. Implement get(key) returning the value or -1, and put(key, value)....
Remove Duplicates From an Unsorted Linked List (从未排序的链表中移除重复元素)
Given the head of an unsorted linked list, remove all nodes that have duplicate values, keeping only the distinct values, and retu...
LFU Cache (LFU 缓存)
Design a Least Frequently Used (LFU) cache with a fixed capacity. get(key) and put(key, value) must run in O(1). On eviction, remo...
Merge k Sorted Lists (合并 K 个升序链表)
You are given an array of k sorted linked lists. Merge them into one sorted list and return its head. Constraints: k is in [0, 10^...
Reverse Nodes in k-Group (K 个一组翻转链表)
Given the head of a linked list, reverse the nodes k at a time and return the modified list. If the number of nodes is not a multi...
Crawler Log Folder (文件夹操作日志搜集器)
You are given a list of folder operations: "../" moves to the parent folder (a no-op at the root), "./" stays in the current folde...
Baseball Game (棒球比赛)
You are keeping score for a baseball game with strange rules. Given a list of operations, return the total score. Operations: an i...
Valid Parentheses (有效的括号)
Given a string s containing only the characters (, ), {, }, [ and ], determine whether the brackets are correctly matched and nest...
Implement Stack using Queues (用队列实现栈)
Implement a last-in-first-out stack using only two queues, supporting push, pop, top and empty. Constraints: 1 <= x <= 9; at...
Implement Queue using Stacks (用栈实现队列)
Implement a first-in-first-out queue using only two stacks, supporting push, pop, peek and empty. Constraints: 1 <= x <= 9; ...
Final Prices With a Special Discount in a Shop (商品折扣后的最终价格)
You are given an array prices where prices[i] is the price of the i-th item. If there is an index j > i with prices[j] <= pr...
Make The String Great (整理字符串)
Given a string s of lower and upper case English letters, a string is great if no two adjacent characters are the same letter in d...
Min Stack (最小栈)
Design a stack supporting push, pop, top and getMin, all in O(1) time. Constraints: -2^31 <= val <= 2^31 - 1; at most 3 * 10...
Evaluate Reverse Polish Notation (逆波兰表达式求值)
You are given an array of strings tokens representing an arithmetic expression in Reverse Polish Notation. Evaluate it and return ...
Removing Stars From a String (从字符串中移除星号)
You are given a string s containing stars *. In one operation you may remove a star and the closest non-star character to its left...
Validate Stack Sequences (验证栈序列)
Given two integer arrays pushed and popped representing the push and pop sequences of a stack, return true if they could have been...
Asteroid Collision (小行星碰撞)
We are given an array asteroids of integers representing asteroids in a row. The absolute value is the size and the sign is the di...
Daily Temperatures (每日温度)
Given an array of daily temperatures, return an array where answer[i] is the number of days you must wait after day i for a warmer...
Online Stock Span (股票价格跨度)
Design a class that collects daily price quotes and returns the span of the stock price for the current day: the number of consecu...
Car Fleet (车队)
There are n cars on a one-lane road heading to a target mile destination. position[i] and speed[i] describe car i. A faster car be...
Simplify Path (简化路径)
Given an absolute Unix-style path, simplify it to its canonical form: it must start with a single /, contain no . or .. components...
Decode String (字符串解码)
Given an encoded string, return its decoded form. The encoding rule is k[encoded_string], meaning the enclosed string repeats exac...
Remove K Digits (移掉 K 位数字)
Given a non-negative integer as a string num and an integer k, remove k digits so that the remaining number is the smallest possib...