-
Notifications
You must be signed in to change notification settings - Fork 780
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
2020-01-09:如何判断单链表交叉? #230
Comments
先有A,B两个链表。A,B同时开始遍历。从A开始遍历,遍历至A链表尾部时转移至B链表开头。从B开始遍历,遍历至B链表尾部时转移至A开头。这样,两个指针相一致处非空即为交叉链表。 |
如果两个链表相交的话,则它们的尾结点一定是相同的,呈横向的“Y”字型,那么最简单的方式就是分别遍历两个链表到结尾,对比结尾的值是否相等就可以了 |
正解。 |
题意不清晰: 1,若两个单链表,则若有相交,则末尾节点相同 |
不赞同。 如果A链表的末尾结点 与 B链表的头结点相交的话,“对比结尾的值是否相等”就不成立了。 |
A链表的末尾节点和B链表的头结点相交,则要么B结点就一个,要么就是A的末尾结点不是真的末尾结点。。。不如,A肯定会继续B的往下面走。 |
这个题应该是问假如两个单键表相交,请找出相交的位置的节点。
} |
为什么两链表相交 则尾节点相同?A,B两链表不能走出“X”字型吗 |
是不是交叉点意味着内存地址相同?如果这样就能解释一定是Y字型 |
No description provided.
The text was updated successfully, but these errors were encountered: