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.
Find the Index of the First Occurrence in a String (找出字符串中第一个匹配项的下标)
Given two strings haystack and needle, return the index of the first occurrence of needle in haystack, or -1 if needle is not part...
Wiggle Sort (摆动排序)
Given an unsorted array nums, reorder it in place so that nums[0] <= nums[1] >= nums[2] <= nums[3] >= .... Constraints...
Largest Number (最大数)
Given a list of non-negative integers nums, arrange them to form the largest possible number and return it as a string. The result...
Continuous Subarray Sum (连续的子数组和)
Given an integer array nums and an integer k, return true if nums has a good subarray: a contiguous subarray of length at least 2 ...
Push Dominoes (推多米诺)
Given a string dominoes where dominoes[i] is 'L', 'R' or '.', return the final state after all falling dominoes settle. A domino p...
Repeated DNA Sequences (重复的 DNA 序列)
The DNA sequence is composed of 'A', 'C', 'G' and 'T'. Given a string s representing a DNA sequence, return all 10-letter-long sub...
Insert Delete GetRandom O(1) (O(1) 时间插入、删除和获取随机元素)
Design a data structure that supports insert(val), remove(val) and getRandom() in average O(1) time. insert returns whether the va...
Check If a String Contains All Binary Codes of Size K (检查一个字符串是否包含所有长度为 K 的二进制子串)
Given a binary string s and an integer k, return true if every binary code of length k appears as a substring of s. Constraints: 1...
Non-decreasing Array (非递减数列)
Given an array nums, return true if it can become non-decreasing by modifying at most one element. Constraints: 1 <= nums.lengt...
Number of Ways to Split Array (分割数组的方案数)
Given an array nums, count the number of ways to split it into two non-empty parts such that the sum of the first part is at least...
Sign of the Product of an Array (数组元素积的符号)
The sign of an array is 1 if the product of all elements is positive, -1 if negative, and 0 if the product is zero. Given nums, re...
Find the Difference of Two Arrays (找出两数组的不同)
Given two arrays nums1 and nums2, return a list of two lists: the distinct elements of nums1 not in nums2, and the distinct elemen...
Uncommon Words from Two Sentences (两句话中的不常见单词)
A word is uncommon if it appears exactly once in either of the two sentences and does not appear in the other. Given two sentences...
Design Parking System (设计停车系统)
Design a parking system with big, medium and small slots. Implement addCar(carType) returning true if a slot of that size is free ...
Shifting Letters II (字母移位 II)
You are given a lowercase string s and a list of shifts, each shifts[i] = [start_i, end_i, direction_i]. Direction 1 shifts the le...
Number of Zero-Filled Subarrays (全 0 子数组的数目)
Given an integer array nums, return the number of subarrays filled with 0. Constraints: 1 <= nums.length <= 10^5, -10^9 <...
Word Subsets (单词子集)
A string a is a subset of string b if every letter of a occurs in b at least as many times. Given words1 and words2, return every ...
Optimal Partition of String (子字符串的最优划分)
Given a string s, partition it into the minimum number of substrings such that each letter appears in at most one substring. Retur...
Design Underground System (设计地铁系统)
Design an underground system supporting checkIn(id, stationName, t), checkOut(id, stationName, t) and getAverageTime(startStation,...
Minimum Penalty for a Shop (商店的最少代价)
A shop owner wants to choose an hour i to close, so that the penalty is minimised. The penalty is the number of 'N' customers befo...
Champagne Tower (香槟塔)
Champagne is poured into the top glass of a tower. Each glass holds exactly 1 unit; excess spills equally into the two glasses bel...
Sum of Absolute Differences in a Sorted Array (有序数组中差绝对值之和)
Given an array nums sorted in non-decreasing order, return an array where result[i] is the sum of |nums[i] - nums[j]| over all j. ...
Design a Food Rating System (设计食物评分系统)
Design a food rating system. Each food has a cuisine and a rating. Implement changeRating(food, newRating) and highestRated(cuisin...
Convert an Array Into a 2D Array With Conditions (转换二维数组)
You are given an integer array nums. Create a 2D array where the i-th row contains the i-th occurrence of each distinct value, and...