[LeetCode]Remove Duplicates from Sorted List(Java)

原创 2016年08月29日 19:37:14

这个题基本没什么机灵可以抖

public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode p = head;
        ListNode q = null;
        while(p!=null){
            q = p.next;
            if(q == null)
                break;
            if(p.val == q.val){
                p.next = q.next;
                q = null;
            }else{
                p = p.next;                
            }
            

            
        }
        return head;
    }
    
}

2016/8/28

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

LeetCode 83 — Remove Duplicates from Sorted List(C++ Java Python)

题目:http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/ Given a sorted linked list, ...

【LeetCode-面试算法经典-Java实现】【082-Remove Duplicates from Sorted List II(排序链表中删除重复元素II)】

【082-Remove Duplicates from Sorted List II(排序链表中删除重复元素II)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Give...

LeetCode 82之Remove Duplicates from Sorted List II的Java题解

题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only dist...

(Leetcode 82) Remove Duplicates from Sorted List II (Java)

题目:Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have...

【LeetCode-面试算法经典-Java实现】【083-Remove Duplicates from Sorted List(排序的单链表中删除重复的结点)】

【083-Remove Duplicates from Sorted List(排序的单链表中删除重复的结点)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given ...

LeetCode :: Remove Duplicates from Sorted List[详细分析]

Given a sorted linked list, delete all duplicates such that each element appear only once. For ex...

Remove Duplicates from Sorted List--LeetCode

题目: Given a sorted linked list, delete all duplicates such that each element appear only once. Fo...

LeetCode82:Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct num...

Remove Duplicates from Sorted List II--LeetCode

题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinc...

[LeetCode] Remove Duplicates from Sorted List II

给定一个已经排序的单链表,删除所有有相同数字的节点,只留下原始链表中的不同数字。...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[LeetCode]Remove Duplicates from Sorted List(Java)
举报原因:
原因补充:

(最多只允许输入30个字)