ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [못품/릿코드/javascript] 142.Linked List Cycle 2
    카테고리 없음 2023. 3. 25. 15:15
        let s = head, f = head;
        while(f && f.next && f.next.next){
            s = s.next;
            f = f.next.next;
            if(s === f){
              //주기가 있는지(다시 되돌아가는 포인터가 있는지 확인하는 과정)
                while(s !== head){
                  //다시 되돌아가는 포인트를 확인하는 과정
                  //물이라고 생각하기 병목현상!
                    head = head.next;
                    s = s.next;
                }
                return s;
            }
        }
        return null;

     

Designed by Tistory.