Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.
The code uses the same node structure described in the theory.
class ListNode{
int val;
public ListNode next;
public ListNode(int val){
this.val = val;
}
public boolean hasNext(){
return next != null;
}
}