8道经典链表常考题目
例1-a:链表逆序(easy)206 Reverse Linked List
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode reverseList(ListNode head) { ListNode new_head=null; while(head!=null) { ListNode next=head.next;//备份 head.next=new_head; new_head=head; head=next; } return new_head; } }
例1-b:链表逆序2(medium)
例2:链表求交点(easy)
例3:链表求环(medium)
例4:链表划分(medium)
例5:复杂链表的复制(hard)
例6-a:2个排序链表归并(easy)
例6-b:K个排序链表归并(hard)
LeetCode206 链表逆序