We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
again this question is bugged... the example of the cycle:
1 -> 2 -> 3 -> 1 -> NULL
1 can't point to both 1 and NULL!
At least this time the ro class compiles!
static bool hasCycle(SinglyLinkedListNode head) {
var d = new HashSet<SinglyLinkedListNode>();
while(head is not null){
if(d.Contains(head)) return true;
d.Add(head);
head = head.next;
}
return false;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
again this question is bugged... the example of the cycle:
1 can't point to both 1 and NULL!
At least this time the ro class compiles!