LeetCode常见题型——回溯法

1. 算法思想

回溯法(backtracking)是优先搜索的一种特殊情况,又称为试探法,常用于需要记录节点状态的深度优先搜索。

排列、组合、选择类问题使用回溯法比较方便。

回溯步骤:修改当前节点状态-》递归子节点-》回改当前节点状态。

注意点:按引用或全局记录状态,所有状态修改在递归完成后需回退,才能继续进行下一节点的访问。

修改有两种情况:一种是修改最后一位输出,比如排列组合;一种是修改访问标记,比如矩阵里搜字符串。

2.常见题型

LeetCode-46. Permutations [C++][Java]_贫道绝缘子的博客-优快云博客Given an arraynumsof distinct integers, returnall the possible permutations. You can return the answer inany order.https://blog.youkuaiyun.com/qq_15711195/article/details/123301860LeetCode-47. Permutations II [C++][Java]_贫道绝缘子的博客-优快云博客Given a collection of numbers,nums,that might contain duplicates, returnall possible unique permutationsin any order.https://blog.youkuaiyun.com/qq_15711195/article/details/123302599LeetCode-77. Combinations [C++][Java]_贫道绝缘子的博客-优快云博客Given two integersnandk, returnall possible combinations ofknumbers out of the range[1, n]. You may return the answer inany order.https://blog.youkuaiyun.com/qq_15711195/article/details/123305538LeetCode-79. Word Search [C++][Java]_贫道绝缘子的博客-优快云博客Given anm x ngrid of charactersboardand a stringword, returntrueifwordexists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cehttps://blog.youkuaiyun.com/qq_15711195/article/details/123306202LeetCode-51. N-Queens [C++][Java]_贫道绝缘子的博客-优快云博客Then-queenspuzzle is the problem of placingnqueens on ann x nchessboard such that no two queens attack each other. Given an integern, returnall distinct solutions to then-queens puzzle.https://blog.youkuaiyun.com/qq_15711195/article/details/123307536LeetCode-52. N-Queens II [C++][Java]_贫道绝缘子的博客-优快云博客Then-queenspuzzle is the problem of placingnqueens on ann x nchessboard such that no two queens attack each other. Given an integern, returnthe number of distinct solutions to then-queens puzzle.https://blog.youkuaiyun.com/qq_15711195/article/details/123311096LeetCode-39. Combination Sum [C++][Java]_贫道绝缘子的博客-优快云博客You may return the combinations inany order. Thesamenumber may be chosen fromcandidatesanunlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different.https://blog.youkuaiyun.com/qq_15711195/article/details/123312301LeetCode-40. Combination Sum II [C++][Java]_贫道绝缘子的博客-优快云博客Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sum totarget. Each number incandidatesmay only be usedoncein the combination.https://blog.youkuaiyun.com/qq_15711195/article/details/123312030LeetCode-37. Sudoku Solver [C++][Java]_贫道绝缘子的博客-优快云博客Write a program to solve a Sudoku puzzle by filling the empty cells.https://blog.youkuaiyun.com/qq_15711195/article/details/123313416

LeetCode-46. Permutations [C++][Java]_贫道绝缘子的博客-优快云博客Given an arraynumsof distinct integers, returnall the possible permutations. You can return the answer inany order.https://blog.youkuaiyun.com/qq_15711195/article/details/123301860LeetCode-47. Permutations II [C++][Java]_贫道绝缘子的博客-优快云博客Given a collection of numbers,nums,that might contain duplicates, returnall possible unique permutationsin any order.https://blog.youkuaiyun.com/qq_15711195/article/details/123302599

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贫道绝缘子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值