题库chevron_right分类chevron_right回溯
undo

回溯

88 道题目
简单: 3中等: 58困难: 27

回溯 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
17

电话号码的字母组合

Generate all letter combinations a digit string can represent using backtracking with pruning, leveraging hash table map…

中等
22

括号生成

Generate Parentheses requires generating all valid combinations of parentheses with given pairs using backtracking and s…

中等
37

解数独

Solve the Sudoku puzzle by filling empty cells while respecting Sudoku's rules using array scanning and backtracking.

困难
39

组合总和

Find all unique combinations of numbers from a distinct array that sum to a target using controlled backtracking search.

中等
40

组合总和 II

Find all unique combinations of numbers that sum to a target using backtracking with careful pruning to avoid duplicates…

中等
46

全排列

Generate all possible orderings of a distinct integer array using backtracking search with careful pruning to avoid dupl…

中等
47

全排列 II

Generate all unique permutations of an array containing duplicates using backtracking and pruning to avoid repeated sequ…

中等
51

N 皇后

Solve the N-Queens problem using backtracking with pruning, exploring all valid board placements while avoiding conflict…

困难
52

N 皇后 II

Solve the N-Queens II problem using backtracking with pruning to efficiently count all valid placements for n queens on …

困难
77

组合

Generate all combinations of k numbers from the range [1, n] using backtracking and pruning.

中等
78

子集

Generate all subsets of a set of unique integers using backtracking with pruning to avoid duplicates.

中等
79

单词搜索

Solve Word Search with backtracking by exploring adjacent cells to match a target word in a grid.

中等
89

格雷编码

Generate an n-bit Gray Code sequence using backtracking with pruning and bit manipulation techniques.

中等
90

子集 II

Subsets II problem asks to generate unique subsets from an array with possible duplicates using backtracking search with…

中等
93

复原 IP 地址

Restore all valid IP addresses from a string using backtracking with pruning, avoiding invalid segments or leading zeros…

中等
95

不同的二叉搜索树 II

Generate all structurally unique BSTs with values 1 to n using backtracking and recursive tree construction techniques.

中等
113

路径总和 II

Find all root-to-leaf paths in a binary tree where the sum of node values equals a given target using DFS backtracking.

中等
126

单词接龙 II

Find all shortest transformation sequences from beginWord to endWord using a dictionary, leveraging backtracking search …

困难
131

分割回文串

Find all possible palindrome partitioning of a string using backtracking and dynamic programming.

中等
140

单词拆分 II

Given a string and dictionary, return all possible sentences by adding spaces where each word is in the dictionary.

困难
212

单词搜索 II

Solve the Word Search II problem using backtracking with pruning to find all words on a board of characters.

困难
216

组合总和 III

Find all unique combinations of k numbers adding to n using efficient backtracking with pruning in arrays.

中等
257

二叉树的所有路径

Find all root-to-leaf paths in a binary tree using DFS and backtracking, constructing strings for each complete path eff…

简单
282

给表达式添加运算符

Expression Add Operators is solved with backtracking that builds multi-digit operands and tracks multiplication preceden…

困难
301

删除无效的括号

Remove the minimum number of invalid parentheses to generate all possible valid strings efficiently using backtracking a…

困难
306

累加数

Additive Number is solved by trying the first two splits, then pruning aggressively while verifying each required sum in…

中等
357

统计各位数字都不同的数字个数

The problem asks to count numbers with unique digits from 0 to 10^n using dynamic programming, math, and backtracking te…

中等
401

二进制手表

Binary Watch involves generating possible times on a binary watch given a number of turned-on LEDs.

简单
473

火柴拼正方形

The problem asks to determine if we can use matchsticks to form a square, exploring dynamic programming and backtracking…

中等
491

非递减子序列

Return all possible non-decreasing subsequences with at least two elements from the input array, nums.

中等
494

目标和

Target Sum requires counting all expressions from nums using '+' or '-' that evaluate exactly to the given target intege…

中等
526

优美的排列

The Beautiful Arrangement problem asks for the number of valid permutations of n integers satisfying specific divisibili…

中等
638

大礼包

Minimize the cost of purchasing items using available special offers with state transition dynamic programming.

中等
679

24 点游戏

Solve the 24 Game by arranging four card numbers using arithmetic operators and parentheses to reach exactly 24 efficien…

困难
691

贴纸拼词

Determine the minimum number of stickers needed to spell a target word using array scanning and hash lookups for efficie…

困难
698

划分为k个相等的子集

Determine if an integer array can be partitioned into k subsets where each subset sums to the same value using DP and ba…

中等
773

滑动谜题

Determine the minimum moves to solve a 2x3 sliding puzzle using BFS and state transition dynamic programming techniques …

困难
784

字母大小写全排列

Letter Case Permutation involves generating all possible strings by changing the case of each letter in a given string.

中等
797

所有可能的路径

Find all paths in a directed acyclic graph (DAG) from source to target using depth-first search and backtracking.

中等
816

模糊坐标

Find all valid 2D coordinate possibilities for an ambiguous input string using backtracking and pruning techniques.

中等
842

将数组拆分成斐波那契序列

This problem challenges you to split a string into a Fibonacci-like sequence using backtracking and pruning.

中等
949

给定数字能组成的最大时间

Given four digits, determine the latest valid 24-hour time possible using each digit exactly once with backtracking.

中等
967

连续差相同的数字

Generate all n-digit numbers where consecutive digits differ by k using efficient backtracking and BFS techniques.

中等
980

不同路径 III

Solve the Unique Paths III problem using backtracking search with pruning to count 4-directional paths covering all empt…

困难
988

从叶结点开始的最小字符串

Determine the lexicographically smallest string from a leaf to root using binary-tree traversal and careful state tracki…

中等
996

平方数组的数目

Count the number of squareful arrays from the given list of integers by checking adjacent pairs' sums for perfect square…

困难
1079

活字印刷

Compute all unique non-empty sequences from given letter tiles using backtracking search with pruning efficiently.

中等
1096

花括号展开 II

Solve Brace Expansion II efficiently by using stack-based state management to generate all unique combinations of nested…

困难
1219

黄金矿工

Find the path with the maximum gold in a grid with backtracking and pruning techniques to maximize the gold collected.

中等
1238

循环码排列

Generate a circular permutation from a range of numbers using backtracking and bit manipulation.

中等
1239

串联字符串的最大长度

Find the maximum length of a concatenated string from an array with all unique characters using backtracking search with…

中等
1240

铺瓷砖

Tiling a Rectangle with the Fewest Squares problem asks for the minimum number of squares required to cover a rectangle …

困难
1255

得分最高的单词集合

Calculate the highest total score by selecting words from a list using available letters, respecting individual letter s…

困难
1286

字母组合迭代器

Implement an iterator that generates all combinations of a given length using efficient backtracking with pruning.

中等
1307

口算难题

Check if a verbal arithmetic equation can be solved using a valid digit-letter mapping.

困难
1415

长度为 n 的开心字符串中字典序第 k 小的字符串

Given n and k, find the k-th lexicographical happy string of length n using backtracking search with pruning.

中等
1467

两个盒子中球的颜色数相同的概率

Compute the probability that two boxes contain the same number of distinct balls using careful combinatorial and DP meth…

困难
1593

拆分字符串使唯一子字符串的数目最大

Maximize unique substrings in a string using backtracking with pruning and hash tables to track substrings.

中等
1601

最多可达成的换楼请求数目

Find the maximum number of achievable transfer requests between buildings with constraints on net employee transfers.

困难
1655

分配重复整数

Determine if you can allocate integers to satisfy customer quantities using state transition dynamic programming techniq…

困难
1718

构建字典序最大的可行序列

Construct the Lexicographically Largest Valid Sequence problem involves finding the largest sequence with backtracking a…

中等
1723

完成所有工作的最短时间

Minimize the maximum working time of k workers by optimally assigning jobs, leveraging dynamic programming and bit manip…

困难
1774

最接近目标价格的甜点成本

Find the closest dessert cost to a target by selecting from a list of base flavors and topping combinations using dynami…

中等
1799

N 次操作后的最大分数和

Maximize the score after n operations by selecting pairs from the array and using their GCD with dynamic programming or …

困难
1849

将字符串拆分为递减的连续值

Check if a string of digits can be split into descending consecutive values where the difference between them is 1.

中等
1863

找出所有子集的异或总和再求和

Compute the sum of all subset XOR totals using a backtracking search with pruning for arrays of small size.

简单
1947

最大兼容性评分和

Assign students to mentors to maximize total compatibility using state transition dynamic programming with bitmask optim…

中等
1980

找出不同的二进制字符串

Find a binary string of length n not in the input array using array scanning and hash lookup efficiently.

中等
1986

完成任务的最少工作时间段

Find the minimum number of work sessions needed to finish a set of tasks, considering task durations and session time.

中等
2002

两个回文子序列长度的最大乘积

Find two disjoint palindromic subsequences in a string to maximize the product of their lengths efficiently using dynami…

中等
2014

重复 K 次的最长子序列

Find the longest subsequence repeated k times in a string using backtracking search with pruning.

困难
2044

统计按位或能得到最大值的子集数目

Determine the number of non-empty subsets that achieve the maximum bitwise OR using efficient backtracking and pruning s…

中等
2048

下一个更大的数值平衡数

Find the smallest numerically balanced number greater than a given integer using backtracking search and pruning.

中等
2056

棋盘上有效移动组合的数目

Given a set of pieces on a chessboard, calculate the number of valid move combinations without overlap using backtrackin…

困难
2065

最大化一张图中的路径价值

Calculate the maximum path quality in a graph using backtracking and pruning to optimize node visits within time limits …

困难
2151

基于陈述统计最多好人数

Determine the maximum number of good people in a group given mutual statements, using precise backtracking with pruning.

困难
2178

拆分成最多数目的正偶数之和

Determine the largest set of unique positive even integers that sum to a given finalSum using backtracking and greedy se…

中等
2212

射箭比赛中的最大得分

In the "Maximum Points in an Archery Competition" problem, Bob aims to maximize his score while respecting Alice's arrow…

中等
2305

公平分发饼干

The problem focuses on fairly distributing cookies among children to minimize the maximum unfairness of the distribution…

中等
2375

根据模式串构造最小数字

Construct the lexicographically smallest string that fits the increasing and decreasing conditions of a given pattern.

中等
2397

被列覆盖的最多行数

Select exactly numSelect columns from a binary matrix to maximize rows where all ones are covered efficiently using back…

中等
2597

美丽子集的数目

Count all non-empty subsets of an array where no two numbers have an absolute difference equal to k, using array scannin…

中等
2698

求一个整数的惩罚数

Find the punishment number of a given integer using backtracking search with pruning.

中等
2708

一个小组的最大实力值

Maximize the strength of a student group by carefully selecting students based on their scores, using dynamic programmin…

中等
2767

将字符串分割为最少的美丽子字符串

Partition a binary string into the fewest beautiful substrings using state transition dynamic programming and careful su…

中等
3211

生成不含相邻零的二进制字符串

Generate all binary strings of length n without adjacent zeros using backtracking search with pruning for efficient enum…

中等
3348

最小可整除数位乘积 II

Find the smallest zero-free number at least as large as num whose digits multiply to a product divisible by t using care…

困难
3376

破解锁的最少时间 I

Solve the Minimum Time to Break Locks I problem using state transition dynamic programming to minimize the time to break…

中等

关联高频模式

LeetCode 回溯题型题解:88题训练路线