Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

移除链表元素 #3

Open
Aras-ax opened this issue Mar 4, 2019 · 0 comments
Open

移除链表元素 #3

Aras-ax opened this issue Mar 4, 2019 · 0 comments

Comments

@Aras-ax
Copy link
Owner

Aras-ax commented Mar 4, 2019

删除链表中等于给定值val的所有节点。

示例:

输入:head =  1->2->6->3->4->5->6, target= 6
输出: 1->2->3->4->5

解答

// 节点对象
function listNode(val) {
    this.val = val;
    this.next = null;
}
// head = new ListNode(x)
function removeNode(head, target) {
    if (head === null) {
        return null;
    }

    head.next = removeNode(head.next, target);
    return head.val === target ? head.next : head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant