1. /**
    2. * Definition for singly-linked list.
    3. * function ListNode(val, next) {
    4. * this.val = (val===undefined ? 0 : val)
    5. * this.next = (next===undefined ? null : next)
    6. * }
    7. */
    8. /**
    9. * @param {ListNode} head
    10. * @return {ListNode}
    11. */
    12. var middleNode = function(head) {
    13. let list = [],
    14. node = head
    15. while(node) {
    16. list.push(node)
    17. node = node.next
    18. }
    19. return list[Math.floor(list.length / 2)]
    20. };