diff options
| author | mo <mokha@cisco.com> | 2017-06-17 09:13:04 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-06-17 09:13:04 -0600 |
| commit | 718a1399e24429dbb089d798209885bfd19b71c1 (patch) | |
| tree | 407c806a0d0a3a6105a0bd3933e753fadc7c1c66 /lib | |
| parent | 50efcb10f4c5748b90da31555fb814fa3ac7e819 (diff) | |
rename variables.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/detect_circles.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/detect_circles.rb b/lib/detect_circles.rb index c584980..7ccaa47 100644 --- a/lib/detect_circles.rb +++ b/lib/detect_circles.rb @@ -4,13 +4,15 @@ A circle means, a -> b -> c -> b, then it is a circle DOC require 'byebug' -def circle?(list) - tortoise, hare = list, list.next_item +def circle?(head) + return false if head.nil? + + tortoise, hare = head, head.next_item until hare.nil? return true if tortoise == hare tortoise = tortoise.next_item - hare = hare.next_item.next_item + hare = hare.next_item&.next_item end return false |
