[LeetCode] Remove Duplicates from Sorted List II
来源:互联网 发布:360下载不了软件 编辑:程序博客网 时间:2024/06/01 13:24
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1->2->3, return 2->3
相关问题1:压缩字符串
相关问题2:Remove Duplicates from Sorted Linked List I 从排序链表中去掉重复值
相关问题3:[LeetCode] Remove Duplicates From Sorted Array I
相关问题 4:[LeetCode] Remove Duplicates From Sorted Array II代码:
/** * 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) { int count = 0; ListNode* newHead=NULL; ListNode* slow = NULL; ListNode* fast = head; if(head==NULL) return NULL; if(head->next==NULL) return head; while(fast->next) { if(fast->val==fast->next->val) // A[j-1]==A[j] { count++; fast=fast->next; } else // A[j-1]!=A[j] { count++; if(count==1) { if(slow==NULL) newHead = fast; else slow->next = fast; slow = fast; fast = fast->next; slow->next=NULL; count=0; } else { fast = fast->next; count = 0; } } } count++; if(count==1) { if(slow==NULL) newHead = fast; else slow->next = fast; slow = fast; slow->next=NULL; } fast = fast->next; return newHead; }};
0 0
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List II
- [leetcode]Remove Duplicates from Sorted List II
- LeetCode-Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- LeetCode - Remove Duplicates from Sorted List II
- LeetCode | Remove Duplicates from Sorted List II
- LeetCode:Remove Duplicates from Sorted List II
- 【leetcode】Remove Duplicates from Sorted List II
- Leetcode: Remove Duplicates from Sorted List II
- leetcode Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- Delphi XE 之路(1)第一个APP
- hive2hbase
- C++中结构体数据的文件读写
- Java的String类的subString()方法使用方法
- [转]“What is the location of the directory of C header
- [LeetCode] Remove Duplicates from Sorted List II
- 第十七周项目5-玩日期时间
- Codeforces Round #283 (Div. 2) A B C
- PiLarm: 便携式树莓派警报器(红外感应+拍照+警报)
- C语言和MYSQL数据库(3)
- JS按回车键实现登录的方法
- jstl标签的用法大全
- 项目3-体重问题
- connection timed out waiting for input: auto-logout