-
Notifications
You must be signed in to change notification settings - Fork 13k
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
feat(chapter_backtracking): Add js and ts codes for chapter 13.3 #667
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuan0221 Thank you for your clean code! Please address the following code.
/* 回溯算法:子集和 I */ | ||
function backtrack(state, target, choices, start, res) { | ||
// 子集和等于 target 时,记录解 | ||
if (target == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (target == 0) { | |
if (target === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address with others, in JS and TS, we use === instead of == now.
console.log(`A = ${JSON.stringify(A)}`); | ||
console.log(`B = ${JSON.stringify(B)}`); | ||
console.log(`C = ${JSON.stringify(C)}`); | ||
solveHanota(A, B, C); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solveHanota(A, B, C); | |
solveHanota(A, B, C); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our code basis is Java code, addressed with others.
} | ||
|
||
/* 构建二叉树 */ | ||
function buildTree(preorder: number[], inorder: number[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function buildTree(preorder: number[], inorder: number[]) { | |
function buildTree(preorder: number[], inorder: number[]): TreeNode | null { |
0, | ||
0, | ||
inorder.length - 1 | ||
) as TreeNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) as TreeNode; | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to use as here.
all done,thx. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thank you! @yuan0221
If this PR is related to coding or code translation, please fill out the checklist and paste the console outputs to the PR.