diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/141. Linked List Cycle" "b/leetcode3/\354\240\225\354\247\204\354\230\201/141. Linked List Cycle" new file mode 100644 index 00000000..6071c134 --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/141. Linked List Cycle" @@ -0,0 +1,26 @@ +/** + * Definition for singly-linked list. + * function ListNode(val) { + * this.val = val; + * this.next = null; + * } + */ + +/** + * @param {ListNode} head + * @return {boolean} + */ +var hasCycle = function(head) { + let curr = head; + let visited = new Set(); + + while (curr !== null){ + if (visited.has(curr)){ + return true; + } + visited.add(curr); + curr = curr.next; + } + + return false; +};