In this Leetcode Linked List Cycle II problem solution we have Given a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if some node in the list can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that the tail's next pointer is connected to. Note that pos is not passed as a parameter. Notice that you should not modify the linked list.

## Problem solution in Python.

```class Solution:
def hasCycle(self, head: ListNode) -> bool:
dict1 = dict()
while(current):
if(current in dict1):
return True
dict1[current] = None
current = current.next
return False
```

## Problem solution in Java.

```public ListNode detectCycle(ListNode head) {
do {
if (fast == null || fast.next == null) {
return null;
}
slow = slow.next;
fast = fast.next.next;
} while (fast != slow);

while (slow != fast) {
slow = slow.next;
fast = fast.next;
}
return slow;
}
```

## Problem solution in C++.

```class Solution {
public:
ListNode *resultNode;

resultNode = nullptr;
}

while(fast !=nullptr && fast->next !=nullptr && slow !=nullptr){
slow = slow->next;
fast = fast->next->next;
if(slow == fast){
while(slow != fast){
slow = slow->next;
fast = fast->next;
}
resultNode = slow;
return resultNode;
}
}

resultNode = nullptr;
return resultNode;
}
};
```

## Problem solution in C.

```struct ListNode *detectCycle(struct ListNode *head) {

return NULL;
}

while (fast != NULL && fast->next != NULL) {

slow = slow->next;
fast = fast->next->next;

if (slow == fast) {
break;
}
}

if (fast == NULL || fast->next == NULL) {
return NULL;
}