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.
Candy Crush (粉碎糖果)
Implement Candy Crush on an m x n board of integers (1-3 for candy types, 0 for empty). Repeatedly: (1) mark all candies that are ...
Find Smallest Common Element in All Rows (找出所有行中最小的公共元素)
Given an m x n matrix mat where every row is sorted in strictly increasing order, return the smallest common element in all rows. ...
One Edit Distance (相隔为 1 的编辑距离)
Given two strings s and t, determine whether they are exactly one edit distance apart. A valid edit is inserting one character, de...
Reverse Words in a String II (翻转字符串里的单词 II)
Given a character array s containing a sequence of words separated by single spaces, reverse the order of the words in place. A wo...
Shortest Way to Form String (形成字符串的最短路径)
Given a string source and a string target, return the minimum number of subsequences of source whose concatenation equals target. ...
First Unique Number (第一个唯一数字)
Design a class that supports adding numbers to a stream and returning the first unique (non-repeating) number. Implement showFirst...
Design Tic-Tac-Toe (设计井字棋)
Design a Tic-Tac-Toe game on an n x n board. Implement move(row, col, player) which records the move and returns the winning playe...
Design Snake Game (贪吃蛇游戏)
Design a Snake game on a width x height grid. The snake starts at (0, 0) with length 1. Food positions are given in advance. Imple...
Zigzag Iterator (锯齿迭代器)
Given two vectors v1 and v2, implement an iterator that returns their elements in alternating order, starting with v1. If one vect...
Design A Leaderboard (力扣排行榜)
Design a leaderboard with addScore(playerId, score), top(K) returning the sum of the top K scores, and reset(playerId) setting tha...
Number of Senior Citizens (老人的数目)
Given an array details of passenger information strings, each formatted as "<phone number><gender><age><seat&...
Two Sum (两数之和)
Given an array of integers nums and an integer target, return the indices [i, j] such that nums[i] + nums[j] == target, with i != ...
Max Consecutive Ones (最大连续 1 的个数)
Given a binary array nums, return the maximum number of consecutive 1s in the array. Constraints: 1 <= nums.length <= 10^5, ...
Longest Common Prefix (最长公共前缀)
Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return the em...
String Matching in an Array (数组中的字符串匹配)
Given an array of strings words, return all strings that are a substring of another string in the array, in any order. Constraints...
Group Anagrams (字母异位词分组)
Given an array of strings strs, group the anagrams together. Return the groups in any order. Constraints: 1 <= strs.length <...
Pascal's Triangle (杨辉三角)
Given an integer numRows, return the first numRows rows of Pascal's triangle. In Pascal's triangle, each number is the sum of the ...
Remove Element (移除元素)
Given an integer array nums and an integer val, remove all occurrences of val in place. The order of the remaining elements may ch...
Unique Email Addresses (独特的电子邮件地址)
Every valid email address consists of a local name, an @, and a domain name. In the local name, periods are ignored and everything...
Isomorphic Strings (同构字符串)
Given two strings s and t, determine if they are isomorphic: every character of s can be replaced to get t, with a consistent one-...
Can Place Flowers (种花问题)
You have a long flowerbed in which some plots are planted and some are not, given as a binary array flowerbed. Flowers cannot be p...
Majority Element (多数元素)
Given an array nums of size n, return the majority element -- the element that appears more than n / 2 times. You may assume the m...
Maximum Difference Between Even and Odd Frequency I (奇偶频次间的最大差值 I)
Given a string s, find the maximum difference between the frequency of a character appearing an even number of times and the frequ...
Next Greater Element I (下一个更大元素 I)
You are given two arrays nums1 and nums2 where nums1 is a subset of nums2. For each element of nums1, find the first element to it...