Code

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode curt = head;
        while (curt.next != null) {
            if (curt.next.val == curt.val) {
                curt.next = curt.next.next;
            }else{
                curt = curt.next;
            }
        }
        return head;
    }
}

results matching ""

    No results matching ""