Examples: LinkedList: 1->2 , Head = 1 InsertAtHead(Head,1) ==> 1->1->2 InsertAtHead(Head,2) ==> 2->1->2 InsertAtHead(Head,3) ==> 3->1->2
ListNode
object and set that as the head of the list. Watch out for empty lists!
ListNode
- newNode
head
is null, return newNode
newNode.next = head
newNode
public ListNode insertAtHead(ListNode head, int data) { }
C
Java
Python