Skip to content

Instantly share code, notes, and snippets.

@mjstromberg
Created July 10, 2021 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjstromberg/9b6bcb94547525de658bc9891a1b6257 to your computer and use it in GitHub Desktop.
Save mjstromberg/9b6bcb94547525de658bc9891a1b6257 to your computer and use it in GitHub Desktop.
function detectLoopInLinkedList(node) {
if (node.isVisited) {
return true;
} else if (node.next) {
node.isVisited = true;
return detectLoopInLinkedList(node.next);
} else {
return false;
}
}
class Node {
constructor(value = null, next = null) {
this.value = value;
this.next = next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment