Here is my method


  • 0
    A
        class Solution {
    public:
        //set<ListNode*> visit; 
        ListNode *detectCycle(ListNode *head) {
            ListNode *t;
            while ( head != NULL )
            {
               if ( (int)(head ->val) == ( 1 <<17 ) )
               {
                   //head ->next = (ListNode*)( (int)(head ->next) * -1 ); 
                   return head;
               }
               head ->val = 1 << 17;
               head = head ->next;
            }
            return NULL;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.