83

删除链表中重复元素, faster than 56%

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

你可能感兴趣的:(83)