/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null){
return head;
}
ListNode p=head;
while(p.next!=null){
if(p.val==p.next.val){
p.next=p.next.next;
}else{
p=p.next;
}
}
return head;
}
}
Leetcode-83 删除排序链表中的重复元素
最新推荐文章于 2024-08-23 11:46:54 发布