Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # you can write to stdout for debugging purposes, e.g.
- # puts "this is a debug message"
- def solution(a)
- # write your code in Ruby 2.2
- length = slow = fast = 0
- loop do
- fast = a[a[fast]]
- slow = a[slow]
- if fast == slow
- loop do
- fast = a[a[fast]]
- slow = a[slow]
- length += 1
- if fast == slow
- return length
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement