Skip to content
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

Merged
merged 11 commits into from
Aug 3, 2023

Conversation

yuan0221
Copy link
Contributor

@yuan0221 yuan0221 commented Jul 30, 2023

If this PR is related to coding or code translation, please fill out the checklist and paste the console outputs to the PR.

  • I've tested the code and ensured the outputs are the same as the outputs of reference codes.
  • I've checked the codes (formatting, comments, indentation, file header, etc) carefully.
  • The code does not rely on a particular environment or IDE and can be executed on a standard system (Win, macOS, Ubuntu).

@vercel
Copy link

vercel bot commented Jul 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
hello-algo ⬜️ Ignored (Inspect) Visit Preview Aug 3, 2023 1:39am

Copy link
Contributor

@justin-tse justin-tse left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (target == 0) {
if (target === 0) {

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
solveHanota(A, B, C);
solveHanota(A, B, C);

Copy link
Contributor

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[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function buildTree(preorder: number[], inorder: number[]) {
function buildTree(preorder: number[], inorder: number[]): TreeNode | null {

0,
0,
inorder.length - 1
) as TreeNode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) as TreeNode;
)

Copy link
Contributor

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.

@yuan0221
Copy link
Contributor Author

yuan0221 commented Aug 3, 2023

all done,thx.

Copy link
Contributor

@justin-tse justin-tse left a 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

@krahets krahets added the code Code-related label Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Code-related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants