<s> class ListNode : <EOL> def __init__ ( self , x ) : <EOL> self . val = x <EOL> self . next = None <EOL> def __str__ ( self ) : <EOL> if self : <EOL> return "<STR_LIT:{}>" . format ( self . val ) <EOL> else : <EOL> return None <EOL> class Solution : <EOL> def detectCycle ( self , head ) : <EOL> fast , slow = head , head <EOL> while fast and fast . next : <EOL> fast , slow = fast . next . next , slow . next <EOL> if fast is slow : <EOL> fast = head <EOL> while fast is not slow : <EOL> fast , slow = fast . next , slow . next <EOL> return fast <EOL> return None <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> head = ListNode ( <NUM_LIT:1> ) <EOL> head . next = ListNode ( <NUM_LIT:2> ) <EOL> head . next . next = ListNode ( <NUM_LIT:3> ) <EOL> head . next . next . next = head . next <EOL> print Solution ( ) . detectCycle ( head ) </s>
