https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/
我的解法:
/**
* 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 current = head;
if(current == null) return current;
while(current.next != null) {
if(current.val == current.next.val) {
current.next = current.next.next;
}else {
current = current.next;
}
}
return head;
}
}