[leetcode oj 83]Remove Duplicates from Sorted List
来源:互联网 发布:淘宝新店如何刷销量 编辑:程序博客网 时间:2024/04/29 18:41
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) { if(NULL != head) { ListNode* ret = new ListNode(head->val); ListNode* newList = ret; ListNode* cur = head; while(NULL != cur) { if(cur->val != newList->val) { newList->next = new ListNode(cur->val); newList = newList->next; } cur = cur->next; } return ret; } return NULL; }};
不递归就不超时了。。。
0 0
- LeetCode OJ:Remove Duplicates from Sorted List
- [LeetCode OJ]Remove Duplicates from Sorted List
- LeetCode OJ Remove Duplicates from Sorted List
- [leetcode oj 83]Remove Duplicates from Sorted List
- LeetCode(83)Remove Duplicates from Sorted List
- [leetcode 83]Remove Duplicates from Sorted List
- [leetcode]83 Remove Duplicates from Sorted List
- [leetcode 83]Remove Duplicates from Sorted List
- leetcode-83 Remove Duplicates from Sorted List
- leetcode || 83、Remove Duplicates from Sorted List
- LeetCode 83 Remove Duplicates from Sorted List
- LeetCode---(83) Remove Duplicates from Sorted List
- leetcode 83 Remove Duplicates from Sorted List
- LeetCode 83:Remove Duplicates from Sorted List
- leetcode[83]:Remove Duplicates from Sorted List
- Leetcode[83]-Remove Duplicates from Sorted List
- Leetcode #83 Remove Duplicates from Sorted List
- leetcode 83: Remove Duplicates from Sorted List
- 明天不是明天
- cxGrid 设置斑马线 根据记录内容更改字体颜色
- 数据持久化方案(二)SharedPerference
- 开发PHP扩展步骤
- 新人千万不要在 Windows 上使用 Ruby on Rails
- [leetcode oj 83]Remove Duplicates from Sorted List
- SugarCRM源码分析之loadFileMap
- Mac系统上eclipse+tomcat+mysql环境的搭建
- 跨平台APP----对Cordova,APPCan,DCloud,APICloud四大平台的分析(系列二)
- 5.5. Dictionaries(字典)
- 通用C 双循环链表(可直接用于项目)
- Python的基本语法——语句块
- Oracle SQL语句执行步骤
- 华硕BIOS密码表2002-2011