Skip to content

Commit 46b5f5e

Browse files
committed
leetcode 141 补充js版解法
1 parent 0b5744e commit 46b5f5e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

animation-simulation/链表篇/leetcode141环形链表.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
**题目代码**
4040

41+
Java Code:
4142
```java
4243
public class Solution {
4344
public boolean hasCycle(ListNode head) {
@@ -56,3 +57,18 @@ public class Solution {
5657
}
5758
```
5859

60+
JS Code:
61+
```javascript
62+
var hasCycle = function(head) {
63+
let fast = head;
64+
let slow = head;
65+
while (fast && fast.next) {
66+
fast = fast.next.next;
67+
slow = slow.next;
68+
if (fast === slow) {
69+
return true;
70+
}
71+
}
72+
return false;
73+
};
74+
```

0 commit comments

Comments
 (0)