I saw the editorial solutions for this problem, but they are written in an unfamiliar language. I'd like to post my code, which worked, and understand the timing of my solution. I don't understand how to judge Big-O time yet.
def length_of_longest_substring(s) longest_sub,current_sub = "","" s.each_char do |c| if current_sub.include?(c) longest_sub = current_sub if current_sub.length > longest_sub.length current_sub=current_sub[current_sub.index(c)+1..-1]+c else current_sub+=c end end longest_sub = current_sub if current_sub.length > longest_sub.length longest_sub.length end
I assume that since I'm creating strings, my space complexity suffers somewhat. I'm not really sure how I would speed things up with time.