Guest User

Untitled

a guest
Jan 5th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.49 KB | None | 0 0
  1. def length_of_longest_substring(s)
  2.     longest = ""
  3.     for i in 0..s.length
  4.         for j in i..s.length
  5.             brk = false
  6.             s[i, j-i].each_char.with_index do |c, x|
  7.                 s[i, j-i].each_char.with_index do |c2, x2|
  8.                     brk = true if c == c2 && x != x2
  9.                 end
  10.                 break if brk
  11.             end
  12.             longest = s[i, j-i] if (s[i, j-i].length > longest.length && !brk)
  13.         end
  14.     end
  15.     return longest.length
  16. end
Add Comment
Please, Sign In to add comment