Skip to content

Commit a2195bd

Browse files
authored
Create Can-you-get-the-loop-?.py
1 parent 5a24efa commit a2195bd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Codewars/Can-you-get-the-loop-?.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def loop_size(node):
2+
if node is None:
3+
return 0
4+
slow = node
5+
fast = node
6+
flag = 0
7+
while(slow and slow.next and fast and
8+
fast.next and fast.next.next):
9+
if slow == fast and flag != 0:
10+
count = 1
11+
slow = slow.next
12+
while(slow != fast):
13+
slow = slow.next
14+
count += 1
15+
return count
16+
17+
slow = slow.next
18+
fast = fast.next.next
19+
flag = 1
20+
return 0
21+

0 commit comments

Comments
 (0)