83. Remove Duplicates from Sorted List
来源:互联网 发布:discuz怎么调用数据 编辑:程序博客网 时间:2024/06/11 12:34
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
.
#include<stdio.h>#include<stdlib.h>typedef struct ListNode{int val;struct Link *next;}ListNode;struct ListNode *Init(int n){ ListNode * head,*list,*p; head=(ListNode *)malloc(sizeof(ListNode)); head->next=NULL; scanf("%d",&head->val); p=head;int i; for(i=0;i<n-1;i++){ list=(ListNode *)malloc(sizeof(ListNode)); list->next=NULL; scanf("%d",&list->val); p->next=list; p=list; } return head;};struct ListNode* deleteDuplicates(struct ListNode* head) { ListNode * p,*q; p=head; q=head->next; while(p->next){ if(p->val==q->val){ p->next=q->next; q=p->next; } else{ p=q; q=q->next; } } return head;}int main(){ int n; scanf("%d",&n); ListNode *head; head=Init(n); head=deleteDuplicates(head); while(head){ printf("%d ",head->val); head=head->next; } return 0;}
阅读全文
0 0
- [LeetCode]83.Remove Duplicates from Sorted List
- 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 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 【leetcode】83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 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
- 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
- [ArcPy] 初识ArcPy
- HashSet和HashMap的区别
- UGUI结合TexturePacker制作图集
- 剑指offer-重建二叉树
- hdu3549(最大流ford-fulkerson模板)
- 83. Remove Duplicates from Sorted List
- BZOJ[1854][Scoi2010]游戏 匈牙利算法
- SSM项目整合-Maven创建JavaWeb工程
- 凡普金科前端面试题
- 面向对象
- 砝码称重
- 初识Cookie
- 【SDK驱动开发1】中断的使用(以一个dma为例)
- 【福分系统】js有时无法接收controller传回的结果?