[leetcode][list] Remove Duplicates from Sorted List

原创 2015年07月07日 10:17:49

题目:

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

For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
	ListNode *p = head;
	while (p != NULL){
		ListNode *q = p->next;
		while (q != NULL && q->val == p->val){
			ListNode *tmp = q;
			q = q->next;
			delete tmp;
		}
		p->next = q;
		p = p->next;
	}
	return head;
}
};


Remove Duplicates from Sorted List -- LeetCode

原题链接: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/  这是一道比较简单的链表操作的题目,要求是删去有序...
  • linhuanmars
  • linhuanmars
  • 2014年04月23日 11:25
  • 8708

Leetcode_83_Remove Duplicates from Sorted List

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41728739 Given a sorted linked...
  • pistolove
  • pistolove
  • 2014年12月04日 19:20
  • 1501

LeetCode(83)Remove Duplicates from Sorted List

题目如下: Given a sorted linked list, delete all duplicates such that each element appear only once. For...
  • feliciafay
  • feliciafay
  • 2014年01月10日 08:06
  • 2710

[leetcode]Remove Duplicates from Sorted List (删除有序节点的值重复的节点 C语言)

Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that eac...
  • sanmao0816
  • sanmao0816
  • 2015年03月28日 18:17
  • 601

82. Remove Duplicates from Sorted List II Leetcode Python

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb...
  • hyperbolechi
  • hyperbolechi
  • 2015年02月05日 11:48
  • 947

83. Remove Duplicates from Sorted List(python)

Given a sorted linked list, delete all duplicates such that each element appear only once. For exam...
  • qq_28119401
  • qq_28119401
  • 2016年09月18日 21:34
  • 261

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, ...
  • dragon_dream
  • dragon_dream
  • 2014年04月01日 19:43
  • 2469

leetcode:82. Remove Duplicates from Sorted List II(Java)解答

转载请注明出处:z_zhaojun的博客 原文地址:http://blog.csdn.net/u012975705 题目地址:https://leetcode.com/problems/reve...
  • u012975705
  • u012975705
  • 2015年12月27日 00:18
  • 1366

【LeetCode with Python】 Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once. For exam...
  • nerv3x3
  • nerv3x3
  • 2008年12月07日 13:17
  • 940

【LeetCode with Python】 Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb...
  • nerv3x3
  • nerv3x3
  • 2014年08月29日 18:36
  • 2683
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[leetcode][list] Remove Duplicates from Sorted List
举报原因:
原因补充:

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