I can‘t find the following code has problems.


  • 0
    Y
    class Solution {
    public:
    	bool hasCycle(ListNode *head) {
    		ListNode *cur = head;
    		while (cur) {
    			if (cur->next == cur)
    				return true;
    			for (ListNode *p = head; p != cur; p = p->next) {
    				if (cur->next == p)
    					return true;
    			}
    			cur = cur->next;
    		}
    		return false;
    	}
    };

Log in to reply
 

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