it is showing Error - Found cycle in the ListNode please need help
class Solution {
public ListNode oddEvenList(ListNode head)
{
ListNode even=new ListNode(-1);
ListNode pe=even;
ListNode odd=new ListNode(-1);
ListNode po=odd;
ListNode curr=head;
while(curr!=null)
{
if(curr.val%2==0)
{
pe.next=curr;
pe=pe.next;
}
else
{
po.next=curr;
po=po.next;
}
curr=curr.next;
}
po.next=pe.next;
pe.next=null;
return po.next;
}
}