mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
Add JavaScript and TypeScript code of top_k and update some code style (#686)
* Update JS and TS code style * Add JavaScript and TypeScript code of top_k * Update top_k.ts * Apply suggestions from code review Co-authored-by: Justin Tse <xiefahit@gmail.com> * Apply suggestions from code review Co-authored-by: Justin Tse <xiefahit@gmail.com> --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@ -9,7 +9,7 @@ function backtrack(choices, state, n, res) {
|
||||
// 当爬到第 n 阶时,方案数量加 1
|
||||
if (state === n) res.set(0, res.get(0) + 1);
|
||||
// 遍历所有选择
|
||||
for (choice of choices) {
|
||||
for (const choice of choices) {
|
||||
// 剪枝:不允许越过第 n 阶
|
||||
if (state + choice > n) break;
|
||||
// 尝试:做出选择,更新状态
|
||||
|
||||
Reference in New Issue
Block a user