您的位置:首页 > 其它

203. Remove Linked List Elements

2016-06-05 19:28 225 查看
题目:https://leetcode.com/problems/remove-linked-list-elements/

代码:

/**
* Definition for singly-linked list.
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode removeElements(ListNode head, int val) {
if(head == null)
return null;
while(head!=null&&head.val == val)
{
head = head.next;
}
ListNode temp = head;
while(temp!=null&&temp.next!=null)
{
if(temp.next.val==val)
{
temp.next = temp.next.next;
}
else
temp = temp.next;
}
return head;
}
}
2ms
========================================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: