您的位置:首页 > 编程语言 > Java开发

Java实现-删除排序链表的重复元素1

2017-06-07 10:57 519 查看


/**
* Definition for ListNode
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) {
*         val = x;
*         next = null;
*     }
* }
*/
public class Solution {
/**
* @param ListNode head is the head of the linked list
* @return: ListNode head of linked list
*/
public static ListNode deleteDuplicates(ListNode head) {
// write your code here
if(head==null){
return null;
}
ListNode list=head;
while(list.next!=null){
if(list.val==list.next.val){
if(list.next.next==null){
list.next=null;
}else{
ListNode node=list.next;
list.next=node.next;
}
}else{
list=list.next;
}
}
return head;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐