From 10ca05356678365201543e20defbff73ec6016bb Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Mon, 19 Oct 2026 22:34:34 +0900 Subject: [PATCH] Create 141. Linked List Cycle --- .../141. Linked List Cycle" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/141. Linked List Cycle" 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; +};