题目链接:Remove Duplicates from Sorted List
和之前写过的题有点类似,直接上代码。
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null||head.next==null)
return head;
ListNode point = head;
ListNode move = point.next;
while(move!= null){
if(point.val == move.val)
{
move = move.next;
point.next = move;
}
else
{
move = move.next;
point = point.next;
}
}
return head;
}
}