Linked Lists Singly linked list basics
268. Delete the Head
You are given head, the first node of a singly linked list. Delete the first node and return the head of
the list that is left.
A singly linked list is a chain of nodes. Each node holds a value and a pointer to the next node, and the last node's pointer is null. An empty list has no nodes, and its head is null. If the list is empty, there is nothing to delete: return the empty list.
The examples write a list as its values from the head on, so head = [4,1,6] is the list 4 → 1 → 6. The
output shows the node you return the same way, as the list from that node on, and shows null as [].
Example 1
Input: head = [9, -4, 12, 6]
[-4,12,6]Explanation: The node holding 9 is the head, so it goes. The node holding -4 was second, and now it is the head of the list that is left.
Example 2
Input: head = [42]
[]Explanation: The only node is the head. Once it is deleted, the list is empty, so the answer is null.
Example 3
Input: head = []
[]Explanation: The list is empty, so there is no node to delete, and the list stays empty.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
0 ≤ number of nodes ≤ 105-109 ≤ Node.val ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.