Java: few lines, linear time


#1
    public ListNode deleteDuplicates(ListNode A) {
        ListNode prev = A, p1 = A.next;
        while(p1!=null){
            if(p1.val != prev.val){
                prev.next = p1;
                prev = p1;
            }
            p1 = p1.next;
        }
        
        prev.next = p1;
        prev = p1;
        
        return A;
    }

#2

Why we are returning A when we have made changed in prev or how the changes are being affected in A??? Can you plz explAIN.