[leetcode 203] Remove Linked List Elements
2015-12-20 20:34
281 查看
Remove all elements from a linked list of integers that have value val.
Example
Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
Return: 1 --> 2 --> 3 --> 4 --> 5
Credits:
Special thanks to @mithmatt for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
Solution:
Example
Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
Return: 1 --> 2 --> 3 --> 4 --> 5
Credits:
Special thanks to @mithmatt for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
Solution:
struct ListNode* removeElements(struct ListNode* head, int val) { struct ListNode dummy; struct ListNode* p = &dummy; dummy.next = head; while (p->next != NULL) { if (p->next->val == val) // find, delete it { p->next = p->next->next; } else // go on { p = p->next; } } return dummy.next; }
相关文章推荐
- XML应用于处理
- 119,NSArray的基本使用
- video和dvd audio区别:
- 《挑战程序设计竞赛》2.6 数学问题-辗转相除法 AOJ0005 POJ2429 1930(1)
- NRF51822 GPIO
- 《失落的世纪致富经典》卷二:4你要创造财富,而不是与人竞争
- Appium__用户登录&退出
- ucosIII 信号量
- HTML 5 Audio Video中怎样来插入音频和视频?
- 实验五
- 益西拉姆 20135239 +银雪纯 20125225 +马悦 20135235 实验四 实验报告
- 使用xib给label等文字显示控件添加attributed属性
- 求解二进制中1的个数
- 在图片上面添加一个图片,实现12306验证码的选择并获取相关坐标的功能
- id和instancetype的异同
- 卷积神经网络 资料
- UITableView回调函数的执行顺序
- mysql主从复制及半同步
- linux-->touch命令详解
- 用Eclipse跑Hadoop程序的注意事项