Get middle element of the Linked List in Javascript

Given the head of a singly linked list, return the middle node of the linked list using Javascript

If there are two middle nodes, then return the 2nd middle node.

Constraints:

  • The number of nodes in the list is in range [1, 100].
  • 1 <= Node.val <= 100