验证,校对

This commit is contained in:
jaredliw
2021-07-16 00:06:52 +08:00
parent 4a8c81e88e
commit 88fcd88712
14 changed files with 180 additions and 197 deletions

View File

@@ -12,7 +12,7 @@
> 给定一个链表判断链表中是否有环pos代表环的入口若为-1则代表无环
>
> 如果链表中存在环则返回 true 否则返回 false
> 如果链表中存在环则返回 true 否则返回 false
示例1
@@ -56,22 +56,6 @@ 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;
};
```
C++ Code:
```cpp
@@ -92,17 +76,34 @@ public:
};
```
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;
};
```
Python Code:
```py
```python
class Solution:
def hasCycle(self, head: ListNode) -> bool:
fast = head
slow = head
while fast and fast.next:
fast = fast.next.next
low = low.next
if fast == low:
slow = slow.next
if fast == slow:
return True
return False
```