Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created March 7, 2021 18:24
Show Gist options
  • Save MohammedALREAI/fb045d687456a8f7eaabe4fe88f7692b to your computer and use it in GitHub Desktop.
Save MohammedALREAI/fb045d687456a8f7eaabe4fe88f7692b to your computer and use it in GitHub Desktop.
removeElements leetcode
/**
* 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