Linked List Cycle1 [Leetcode][자바스크립트][Easy] 141. Linked List Cycle 풀이1 /** * 141_LinkedListCycle.js * Easy * https://leetcode.com/problems/linked-list-cycle/ */ const nodeArr = []; var hasCycle = function(head) { if (head === null || head.next === null) return false; if (nodeArr.indexOf(head.next) > -1) return true; nodeArr.push(head.next); return hasCycle(head.next); }; 문제 예시에서 input 이 배열로 주어지는 것처럼 나타나서 처음에 좀 헷갈렸다. hasCycle 함수 자체를 재귀로 놓고 돌렸는데 그 결과로 nodeArr 배열이.. 2022. 1. 11. 이전 1 다음