leetcode[203]:Remove Linked List Elements
2015-06-07 14:48
459 查看
Remove Linked List Elements
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.
空链表!!!起始为空,或是删除后为空!!!
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.
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* removeElements(struct ListNode* head, int val) { struct ListNode *L,*tmp; tmp = (struct ListNode*) malloc( sizeof( struct ListNode* ) ); if(head == NULL ) return head; while(head->val == val) { head=head->next; if(head == NULL ) return head; } L=head; while(L->next != NULL){ if(L->next->val == val) { tmp = L->next; L->next = tmp->next; free(tmp); } else L = L->next; } return head; }
空链表!!!起始为空,或是删除后为空!!!
相关文章推荐
- C#中Ilist与list的区别小结
- C#中IList<T>与List<T>的区别深入解析
- C#对list列表进行随机排序的方法
- C++实现的泛型List类分享
- C# Datagridview绑定List方法代码
- javascript radio list的实现细节(多浏览器兼容)
- c++ STL容器总结之:vertor与list的应用
- 大家注意vector, list, set, map成员函数erase
- ASP.NET―001:GridView绑定List、页面返回值具体实现
- List all the Databases on a SQL Server
- js Map List 遍历使用示例
- Java List双击事件实现方法
- velocity显示List与Map的方法详细解析
- 关于STL中list容器的一些总结
- 关于C#泛型列表List<T>的基本用法总结
- Java集合类中文介绍
- use jscript with List Proxy Server Information
- list泛型自定义排序示例
- C#中IEnumerable、ICollection、IList、List之间的区别
- Perl List::Util模块使用实例