If this pull request (PR) pertains to Chinese-to-English translation, please confirm that you have read the contribution guidelines and complete the checklist below:
[ ] This PR represents the translation of a single, complete document, or contains only bug fixes.
[ ] The translation accurately conveys the original meaning and intent of the Chinese version. If deviations exist, I have provided explanatory comments to clarify the reasons.
If this pull request (PR) is associated with coding or code transpilation, please attach the relevant console outputs to the PR and complete the following checklist:
[x] I have thoroughly reviewed the code, focusing on its formatting, comments, indentation, and file headers.
[x] I have confirmed that the code execution outputs are consistent with those produced by the reference code (Python or Java).
[x] The code is designed to be compatible on standard operating systems, including Windows, macOS, and Ubuntu.
9.2.2 基于邻接表的实现中 JS 和 TS 代码片段
removeEdge
函数如果传入的两个顶点不为邻接点,那么在对应邻接表adjList
中查找不到对应的顶点,返回 -1,继续执行则会删除顶点的邻接顶点表最后一项,即splice(-1, 1)
。通过添加边界条件判断两顶点是否为邻接点修复此问题。
If this pull request (PR) pertains to Chinese-to-English translation, please confirm that you have read the contribution guidelines and complete the checklist below:
If this pull request (PR) is associated with coding or code transpilation, please attach the relevant console outputs to the PR and complete the following checklist:
相关代码控制台输出: