Skip to content

Instantly share code, notes, and snippets.

@RP-3
Created April 8, 2020 23:14
Show Gist options
  • Save RP-3/1b9ec98abd1da258391a65083c6d4845 to your computer and use it in GitHub Desktop.
Save RP-3/1b9ec98abd1da258391a65083c6d4845 to your computer and use it in GitHub Desktop.
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var middleNode = function(head) {
let [fast, slow] = [head, head];
while(fast && fast.next){
slow = slow.next;
fast = fast.next.next;
}
return slow;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment