You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* * @lc app=leetcode id=19 lang=typescript * * [19] Remove Nth Node From End of List */// @lc code=start/** * 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) * } * } */functionremoveNthFromEnd(head: ListNode|null,n: number): ListNode|null{constdummy=newListNode(0,head);// the distance between left and right is always nletleft=dummy;letright=head;for(leti=0;i<n;i++){right=right.next;}// right will reach the end of this list// and left would be the prev node of target node that we need to deletewhile(right){left=left.next;right=right.next;}// delete the nodeleft.next=left.next.next;returndummy.next;};// @lc code=end
No description provided.
The text was updated successfully, but these errors were encountered: