链表
anyTimeWithYou
这个作者很懒,什么都没留下…
展开
-
[ListNode链表] 翻转链表
翻转链表时间复杂度:O(1)图解:public Node reverseList(Node head){ //初始化prev=null,cur=head Node prev = null; Node cur = head; // while循环,条件,cur=null while(cur != null){ Node temp = cur.next;//记录cur.next原创 2022-04-05 11:10:58 · 317 阅读 · 0 评论 -
【算法】相交链表问题go语言解决
题目 leetcode 160.链接 [leetcode160](https://leetcode-cn.com/problems/intersection-of-two-linked-lists/)无论两链表是否相交,只需要将链表LA和链表LB的链尾对齐,然后从后向前依次比较节点是否相同即可。1.从后向前访问的第一节点既不是公共节点则两链表不相交。2.从后向前访问的公共节点中最后访问的公共节点则为两链表相交的第一个节点。但单链表想向前遍历节点有点痴人说梦,但是如果将LA+LB和LB+LA的两原创 2022-02-23 19:37:04 · 357 阅读 · 0 评论