Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active November 19, 2015 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/1c3bb9aa53fcbc9e291b to your computer and use it in GitHub Desktop.
Save havenwood/1c3bb9aa53fcbc9e291b to your computer and use it in GitHub Desktop.
Longest Substring Without Repeating Characters
def lols s
s.size.downto(1).find do |n|
s.each_char.each_cons(n).any? do |chars|
!chars.uniq!
end
end
end
%w[abcabcbb bbbbb foobar].map &method(:lols) #=> [3, 1, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment