Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def length_of_longest_substring(s)
- longest = ""
- for i in 0..s.length
- for j in i..s.length
- brk = false
- s[i, j-i].each_char.with_index do |c, x|
- s[i, j-i].each_char.with_index do |c2, x2|
- brk = true if c == c2 && x != x2
- end
- break if brk
- end
- longest = s[i, j-i] if (s[i, j-i].length > longest.length && !brk)
- end
- end
- return longest.length
- end
Add Comment
Please, Sign In to add comment