Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from labuladong:master #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 1 commit into AlgorithmAndLeetCode:master from labuladong:master
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions 算法思维系列/集合划分.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ tags: ['回溯算法']

**-----------**

之前说过回溯算法是笔试中最好用的算法,只要你没什么思路,就用回溯算法暴力求解,即便不能通过所有测试用例,多少能过一点。
我之前说过回溯算法是笔试中最好用的算法,只要你没什么思路,就用回溯算法暴力求解,即便不能通过所有测试用例,多少能过一点。

回溯算法的技巧也不难,前文 [回溯算法框架套路](https://labuladong.github.io/article/fname.html?fname=回溯算法详解修订版) 说过,回溯算法就是穷举一棵决策树的过程,只要在递归之前「做选择」,在递归之后「撤销选择」就行了。
回溯算法的技巧也不算难,前文 [回溯算法框架套路](https://labuladong.github.io/article/fname.html?fname=回溯算法详解修订版) 说过,回溯算法就是穷举一棵决策树的过程,只要在递归之前「做选择」,在递归之后「撤销选择」就行了。

**但是,就算暴力穷举,不同的思路也有优劣之分**。

本文就来看一道非常经典的回溯算法问题,力扣第 698 题「划分为k个相等的子集」。这道题可以帮你更深刻理解回溯算法的思维,得心应手地写出回溯函数。

> note:阅读本文之前,建议先阅读并理解 [回溯算法秒杀排列/组合/子集问题](https://labuladong.github.io/article/fname.html?fname=子集排列组合)。因为本文这道题所求的就是子集的问题,有一些模式和套路和原始的子集问题是非常类似的,可以结合着理解。

题目非常简单:

给你输入一个数组 `nums` 和一个正整数 `k`,请你判断 `nums` 是否能够被平分为元素和相同的 `k` 个子集。
Expand Down
1 change: 1 addition & 0 deletions 高频面试系列/子集排列组合.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ void backtrack(int[] nums) {
- [回溯算法解题套路框架](https://labuladong.github.io/article/fname.html?fname=回溯算法详解修订版)
- [我的刷题心得](https://labuladong.github.io/article/fname.html?fname=算法心得)
- [算法时空复杂度分析实用指南](https://labuladong.github.io/article/fname.html?fname=时间复杂度)
- [经典回溯算法:集合划分问题](https://labuladong.github.io/article/fname.html?fname=集合划分)

</details><hr>

Expand Down

AltStyle によって変換されたページ (->オリジナル) /