[leetcode]Remove Duplicates from Sorted List
来源:互联网 发布:软件质量品质管理 编辑:程序博客网 时间:2024/04/30 00:06
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.
链表的简单应用,一开始没有加if(head==NULL) return head;错了一次,以后要注意=.=
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: map<int,bool> ans; ListNode *deleteDuplicates(ListNode *head) { ListNode * i,*j,*res,*ans; if(head==NULL) return head; res->val = head->val; res->next= NULL; ans = res; bool flag; for(i=head->next;i!=NULL;i=i->next){ flag = false; for(j=head;j!=NULL && j!=i;j=j->next){ if(j->val==i->val) { flag = true; break; } } if(flag==false){ res->next = i; res=res->next; } } res->next = NULL; return ans; }};
0 0
- Remove Duplicates from Sorted List :from LeetCode
- Leetcode - List - Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- leetcode 37: Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List
- GCC Warning ISO C++11 Does not allow conversion from literal string to char*
- 编译内核2.3.4遇到的问题以及解决方案
- javascript弹出窗口实现动态文件上传
- 苹果所有常用证书,appID,Provisioning Profiles配置说明及制作图文教程(精)
- Linux Color
- [leetcode]Remove Duplicates from Sorted List
- JAVA线程安全
- Android的系统架构解析
- 黑马程序员--IO(File类、Properties、IO中其他的一些常用流、字符编码)
- swift 利用原生请求上传多张图片和多个参数到服务器
- 安卓快捷键
- [LeetCode] Search Insert Position
- 指针进阶(二)
- 用Django实现网页Url使用汉语拼音PinYin作为SEO优化的实现方法