Without extra space? can this code work?


  • 0
    4
    public class Solution {
        public boolean hasCycle(ListNode head) {
            if(head==null)return false;
            while(head.next!=null)
            if(head.val!=mark) {
                head.val=-12346;// a special number....
                head=head.next;
                continue;
            }else {
                return true;
            }
            return false;
        }
    }

  • 0
    I

    I don't think you should change the val...


  • 0

    What is that mark? And please indent correctly.


Log in to reply
 

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