Skip to main content
142, Linked List Cycle II

I Problem

Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer.
Internally, pos is used to denote the index of the node that tail's next pointer is connected to (0-indexed). It is -1 if there is no cycle.
Note that pos is not passed as a parameter.


MikeAbout 2 minlinkedlistmediumhash tablelinked listtwo pointers
141, Linked List Cycle

I Problem

Given head, the head of a linked list, determine if the linked list has a cycle in it.

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer.
Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.


MikeAbout 2 minlinkedlisteasyhash tablelinked listtwo pointers
160, Intersection of Two Linked Lists

I Problem

Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

For example, the following two linked lists begin to intersect at node c1:

The test cases are generated such that there are no cycles anywhere in the entire linked structure.


MikeAbout 3 minlinkedlisteasyhash tablelinked listtwo pointers
19, Remove Nth Node From End of List

I Problem

Given the head of a linked list, remove the nᵗʰ node from the end of the list and return its head.

Example 1

Input: head = [1, 2, 3, 4, 5], n = 2
Output: [1, 2, 3, 5]

Example 2
Input: head = [1], n = 1
Output: []


MikeAbout 3 minlinkedlistmediumlinked listtwo pointers
24, Swap Nodes in Pairs

I Problem

Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)

Example 1

Input: head = [1, 2, 3, 4]
Output: [2, 1, 4, 3]


MikeAbout 1 minlinkedlistmediumlinked listrecursion
206, Reverse Linked List

I Problem

Given the head of a singly linked list, reverse the list, and return the reversed list.

Example 1

Input: head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]

Example 2

Input: head = [1, 2]
Output: [2, 1]

Example 3
Input: head = []
Output: []


MikeAbout 1 minlinkedlisteasylinked listrecursion
707, Design Linked List

I Problem

Design your implementation of the linked list. You can choose to use a singly or doubly linked list.

A node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer reference to the next node. If you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.


MikeAbout 6 minlinkedlistmediumlinked listdesign
203, Remove Linked List Elements

I Problem

Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.

Example 1

Input: head = [1, 2, 6, 3, 4, 5, 6], val = 6
Output: [1, 2, 3, 4, 5]

Example 2
Input: head = [], val = 1
Output: []


MikeAbout 1 minlinkedlisteasylinked listrecursion