# Middle Node

![](https://3743232000-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHW2IQuh2PFpWJDvBz2FF%2Fuploads%2Fgit-blob-194d2379476fff6e7467e12d920899f2d90c4eed%2F111.png?alt=media)

* n, 1

```jsx
// This is an input class. Do not edit.
class LinkedList {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

exports.LinkedList = LinkedList;

function middleNode(linkedList) {
  
  let count = 0;
  let slow = linkedList;
  let fast = linkedList;
  while (fast.next !== null && fast.next.next !== null) {
    slow = slow.next;
    fast = fast.next.next;

    count++;
  }

  if (fast.next === null) return slow;
  
  return slow.next;
}

// Do not edit the line below.
exports.middleNode = middleNode;
```
