My accepted java solution using recursion/


  • -1
    J

    `public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
    if(head==null||head.next==null){
    return head;
    }
    ListNode x=head;
    int val=x.val;
    int valn=x.next.val;
    if(val==valn){
    x.next=x.next.next;
    }
    else{
    x=x.next;
    }
    deleteDuplicates(x);
    return head;

    }
    

    }`


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.