leetcode 83. Remove Duplicates from Sorted List
来源:互联网 发布:淘宝如何设置主营类目 编辑:程序博客网 时间:2024/05/22 15:35
/** * 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(head == NULL) return NULL; ListNode * here = head->next,*h = head; while(here != NULL){ if(head->val == here->val){ here = here->next; } else { head->next = here; head = head->next; here - here->next; } } head->next =NULL; return h; }};
快一点的
/** * 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(head == NULL) return NULL; ListNode * here = head->next,*h = head; int n = head->val; while(here != NULL){ if(here->val == n){ here = here->next; } else { h->next=here; h = h->next; n=here->val; here=here->next; } } h->next=NULL; return head; }};
0 0
- [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
- 83. Remove Duplicates from Sorted List LeetCode
- 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
- Androird长度单位解析
- linux下查看和添加PATH环境变量
- 继续学习
- Arm汇编学习笔记(六)——函数调用栈空间以及fp寄存器
- clipboard.js实现无flash复制内容到剪贴板
- leetcode 83. Remove Duplicates from Sorted List
- C++ 贪吃蛇基本算法
- powerdesigner16.5将name字段附到comment中,并生成sql
- 面试问题解答记录(2016-08-18)
- Selenium3.0beta版本启动firefox浏览器的问题
- RestFul协议接口和SOAP协议接口
- 二叉树
- Android软键盘弹出时把布局控件顶上去的解决方法
- jquery select下拉框通过text找value