주기 LinkedList 감지 - I
                                            
                                                
                                                
                                                
                                                
                                                
                                                 3947 단어  leetcodejavascript
                    
접근법 1
Temp 포인터를 사용하는 곳입니다.
/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {boolean}
 */
var hasCycle = function(head) {
    let tempNode = new ListNode(0);
    let current = head;
    while(current){
        if(current.next === tempNode){
            return true;
        }
        let saveNext = current.next;
        current.next = tempNode;
        current = saveNext;
    }
    return false;
};
접근법 2
Map을 사용하여(또는 set을 사용하여 수행할 수 있음) 방문한 포인터를 추적합니다.
var hasCycle = function(head) {
    let mapValues = new Map();
    while (head) {
        if (mapValues.has(head)) {
            return true;
        } else {
            mapValues.set(head, "Yes");
            head = head.next;
        }
    }
    return false;
};
접근법 3
추가 포인터를 사용하여 Node 생성 방법을 수정할 수 있는 곳 -(Visited = false(default)) & can traverse list.
방문한 경우 true -> true를 반환하고 그렇지 않으면 false를 반환합니다.
Reference
이 문제에 관하여(주기 LinkedList 감지 - I), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/zeeshanali0704/check-cyclic-linkedlist-i-3j8e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)