[C语言][LeetCode][83]Remove Duplicates from Sorted List
来源:互联网 发布:杭州淘宝代运营收费 编辑:程序博客网 时间:2024/04/29 15:53
题目
Remove Duplicates from Sorted List
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.
标签
Linked List
难度
简单
分析
题目意思是给定一个单链表,去除重复的节点,返回新链表。解题思路是,用一个临时指针指向list,如果p->val == p->next->val,则将p指针跳过p->next,指向p->next->next。
C代码实现
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* deleteDuplicates(struct ListNode* head) { struct ListNode * p; p = head; if(!head) return NULL; while(p && p->next) { if(p->val == p->next->val) p->next = p->next->next; else p = p->next; } return head; }
0 0
- [C语言][LeetCode][83]Remove Duplicates from Sorted List
- [leetcode](Remove Duplicates from Sorted List II C语言实现)
- [C语言][LeetCode][82]Remove Duplicates from Sorted List II
- 【LeetCode】 82. Remove Duplicates from Sorted List II C语言
- 【LeetCode】83. Remove Duplicates from Sorted List C语言
- 【leetcode c++】83 Remove Duplicates from Sorted List
- [leetcode-83]Remove Duplicates from Sorted List(C)
- 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
- ZOJ-3923-In the Rain
- Win7 自带IIS7局域网无法访问解决办法
- CoreLocation.framework框架基本用法
- pat1016:部分A+B
- 杭电1217
- [C语言][LeetCode][83]Remove Duplicates from Sorted List
- 深入理解SetUID
- c++primer(第五版) 第十二章 动态内存习题答案
- Maximal Information Coefficient 最大信息系数
- 在终端上访问网站和下载文件
- pat1017:A除以B
- iOS开发之自定义手势
- 安装oracle客户端,配置plsql
- Spring框架的工作原理