Conversation
There was a problem hiding this comment.
Pull request overview
Adds multi-language reference solutions and write-ups for LeetCode 3558. Number of Ways to Assign Edge Weights I in the solution/3500-3599 section.
Changes:
- Added implementations for the same approach (DFS to compute max depth +
2^(d-1) mod M) in Python/Java/C++/Go/TypeScript. - Expanded the Chinese and English READMEs with an explanation and code tabs for each language.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| solution/3500-3599/3558.Number of Ways to Assign Edge Weights I/Solution.ts | TypeScript implementation of the solution (depth + fast pow). |
| solution/3500-3599/3558.Number of Ways to Assign Edge Weights I/Solution.py | Python implementation of the solution (depth + modular pow). |
| solution/3500-3599/3558.Number of Ways to Assign Edge Weights I/Solution.java | Java implementation of the solution (depth + fast pow). |
| solution/3500-3599/3558.Number of Ways to Assign Edge Weights I/Solution.go | Go implementation of the solution (depth + fast pow). |
| solution/3500-3599/3558.Number of Ways to Assign Edge Weights I/Solution.cpp | C++ implementation of the solution (depth + fast pow). |
| solution/3500-3599/3558.Number of Ways to Assign Edge Weights I/README.md | Chinese explanation + multi-language code tabs. |
| solution/3500-3599/3558.Number of Ways to Assign Edge Weights I/README_EN.md | English explanation + multi-language code tabs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3
to
+7
| def dfs(i: int, fa: int = 0) -> int: | ||
| res = 0 | ||
| for j in g[i]: | ||
| if j != fa: | ||
| res = max(res, dfs(j, i) + 1) |
Comment on lines
+11
to
+15
| const dfs = (i: number, fa: number): number => { | ||
| let res = 0; | ||
| for (const j of g[i]) { | ||
| if (j !== fa) { | ||
| res = Math.max(res, dfs(j, i) + 1); |
Comment on lines
+19
to
+27
| private int dfs(int i, int fa) { | ||
| int res = 0; | ||
| for (int j : g[i]) { | ||
| if (j != fa) { | ||
| res = Math.max(res, dfs(j, i) + 1); | ||
| } | ||
| } | ||
| return res; | ||
| } |
Comment on lines
+13
to
+22
| var dfs func(int, int) int | ||
| dfs = func(i, fa int) int { | ||
| res := 0 | ||
| for _, j := range g[i] { | ||
| if j != fa { | ||
| res = max(res, dfs(j, i)+1) | ||
| } | ||
| } | ||
| return res | ||
| } |
Comment on lines
+14
to
+22
| auto dfs = [&](this auto&& dfs, int i, int fa) -> int { | ||
| int res = 0; | ||
| for (int j : g[i]) { | ||
| if (j != fa) { | ||
| res = max(res, dfs(j, i) + 1); | ||
| } | ||
| } | ||
| return res; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.