您的位置:首页 > 其它

203. Remove Linked List Elements

2016-03-18 00:00 162 查看
递归访问链表,当遇到要删除的值时,返回下一个结点

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