mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2024-11-28 14:58:55 +00:00
leetcode 141 补充js版解法
This commit is contained in:
parent
0b5744e2fa
commit
46b5f5eb7d
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
**题目代码**
|
**题目代码**
|
||||||
|
|
||||||
|
Java Code:
|
||||||
```java
|
```java
|
||||||
public class Solution {
|
public class Solution {
|
||||||
public boolean hasCycle(ListNode head) {
|
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;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user