true
otherwise return false
. Empty lists should be considered non-cyclic.
1->2->3->4->1 ==> true
1->2->3->4 ==> false
Hashtable
. Since the problem mentions that the space complexity can be O(n), you're good with the extra space this would take!
Hashtable
. While traversing through the list if current node is in the hashtable, there is a loop.
public Boolean isCyclic(ListNode head) { }
C
Java
Python