Created
March 7, 2021 18:24
-
-
Save MohammedALREAI/fb045d687456a8f7eaabe4fe88f7692b to your computer and use it in GitHub Desktop.
removeElements leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* class ListNode { | |
* val: number | |
* next: ListNode | null | |
* constructor(val?: number, next?: ListNode | null) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
* } | |
*/ | |
function removeElements(head: ListNode | null, val: number): ListNode | null { | |
if(!head) return null; | |
else { | |
head.next = removeElements(head.next,val); | |
return (head.val===val)?head.next:head | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment