Answers for "figure out if a linked list contains a cycle javascript"

0

figure out if a linked list contains a cycle javascript

function LinkedListNode(value) {
  this.value = value;
  this.next = null;
}
let head = new LinkedListNode(10)
head.next = new LinkedListNode(25)
head.next.next = new LinkedListNode(46)

function hasCycle(head) {
  let node = head;
  let map={};
  while(node){
      if(map[node.value]){
         return {"Found":node}
      }  
    else{
      map[node.value] = true;
    }
    node = node.next;
  }
  return "Not found";
}
hasCycle(head)
Posted by: Guest on November-11-2020

Code answers related to "figure out if a linked list contains a cycle javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language