leetcode——Remove Duplicates from Sorted List II 删除排序字符串中重复字符(AC)
来源:互联网 发布:淘宝外卖怎么加入 编辑:程序博客网 时间:2024/05/11 16:03
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
.
没什么太多讲的,可以使用递归和迭代两种方法来做,要仔细考虑各种输入情况。code如下:
class Solution {public: ListNode *deleteDuplicates(ListNode *head) { if(head == NULL) return NULL; ListNode *first = head,*second = NULL,*result = NULL; bool isDup = false; while(first!=NULL) { isDup = false; while(first->next != NULL && first->val == first->next->val) { isDup = true; first = first->next; } if(!isDup) { if(second == NULL) { second = first; if(result == NULL) result = second; } else { second->next = first; second = second->next; } } first = first->next; } if(second!=NULL) second->next = NULL; return result; }};
0 0
- leetcode——Remove Duplicates from Sorted List II 删除排序字符串中重复字符(AC)
- LeetCode: Remove Duplicates from Sorted Array II(在排序数组中删除重复元素)
- leetCode 82.Remove Duplicates from Sorted List II (删除排序链表的重复II) 解题思路和方法
- 【LeetCode-面试算法经典-Java实现】【082-Remove Duplicates from Sorted List II(排序链表中删除重复元素II)】
- leetcode(83)—— 删除已排序链表重复元素(Remove Duplicates from Sorted List)
- LeetCode | Remove Duplicates from Sorted List II(删除链表中重复结点2)
- LeetCode 82. Remove Duplicates from Sorted List II(删除链表中的重复节点)
- Leetcode Remove Duplicates from Sorted List II 删除链表中重复的元素II
- [Lintcode]Remove Duplicates from Sorted List II 删除排序链表中的重复数字 II
- 26. Remove Duplicates from Sorted Array(从排序数组中删除重复) —— Java
- LeetCode——Remove Duplicates from Sorted List II
- leetcode 081 —— Remove Duplicates from Sorted List II
- 113.Remove Duplicates from Sorted List II-删除排序链表中的重复数字 II(中等题)
- leetcode-82. Remove Duplicates from Sorted List II(删除有序列表中所有重复元素一个不留)
- 82.leetcode Remove Duplicates from Sorted List II(medium)[链表删除重复]
- LeetCode 82 Remove Duplicates from Sorted List II(从已排序链表中移除重复元素)(Linked List)(*)
- (LeetCode)Remove Duplicates from Sorted List --- 链表中删除重复元素
- LeetCode OJ 之 Remove Duplicates from Sorted List II (删除有序链表中重复的数 - 二)
- 多处理机初探
- oprofile 安装指南
- 设计模式之命令模式
- JDK环境变量-Path和ClassPath到底是干什么用的
- const对象为什么可以在头文件中定义
- leetcode——Remove Duplicates from Sorted List II 删除排序字符串中重复字符(AC)
- 在线文档的转换的补充!
- Java线程锁
- EJB WEB服务的客户端开发(版本问题)
- 翻转句子中单词的顺序
- 写给自己亲爱的爸比
- 判断整数序列是不是二元查找树的后序遍历结果
- java 处理word文档 (含图片,表格内容)
- android入门