给定一个有序存在重复的值链表,使得每个元素只出现一次
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode deleteDuplication(ListNode head) {
if (null == head) return null;
ListNode pre = head;
ListNode t = head.next;
while (t != null) {
ListNode next = t.next;
if (pre.val == t.val) {
pre.next = next;
t.next = null;
} else {
pre = pre.next;
}
t = next;
}
return head;
}
} 
京公网安备 11010502036488号