Created
November 4, 2015 19:22
-
-
Save gagaception/6c2be20e9e4807a48628 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LongestSubstring | |
def self.find(first, second) | |
return nil if first.nil? || second.nil? | |
return nil if first != second | |
x, xs, y, ys = first[0..0], first[1..-1], second[0..0], second[1..-1] | |
if x == y | |
x + self.find(xs, ys) | |
else | |
[self.find(first, ys), self.find(xs, second)].max_by {|x| x.size} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment