1. 程式人生 > >LintCode 112---刪除排序鏈表中的重復元素

LintCode 112---刪除排序鏈表中的重復元素

efi let int solution clas spa lis head --

/**
 * Definition for ListNode
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */

public class Solution {
    /**
     * @param head: head is the head of the linked list
     * @return
: head of linked list */ public ListNode deleteDuplicates(ListNode head) { if(head==null||head.next==null){ return head; } ListNode p=head; while(p.next!=null){ if(p.val!=p.next.val){ p
=p.next; } else { p.next=p.next.next; } } return head; } }

LintCode 112---刪除排序鏈表中的重復元素