From 46b5f5eb7d12b5d3eea270c25830f3d45d6a9df7 Mon Sep 17 00:00:00 2001 From: daluozha <561890199@qq.com> Date: Tue, 27 Apr 2021 18:14:29 +0800 Subject: [PATCH] =?UTF-8?q?leetcode=20141=20=E8=A1=A5=E5=85=85js=E7=89=88?= =?UTF-8?q?=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../链表篇/leetcode141环形链表.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/animation-simulation/链表篇/leetcode141环形链表.md b/animation-simulation/链表篇/leetcode141环形链表.md index 528d421..d157030 100644 --- a/animation-simulation/链表篇/leetcode141环形链表.md +++ b/animation-simulation/链表篇/leetcode141环形链表.md @@ -38,6 +38,7 @@ **题目代码** +Java Code: ```java public class Solution { public boolean hasCycle(ListNode head) { @@ -56,3 +57,18 @@ public class Solution { } ``` +JS Code: +```javascript +var hasCycle = function(head) { + let fast = head; + let slow = head; + while (fast && fast.next) { + fast = fast.next.next; + slow = slow.next; + if (fast === slow) { + return true; + } + } + return false; +}; +```