Skip to content

Instantly share code, notes, and snippets.

@roger35972134
Created October 11, 2017 06:00
Show Gist options
  • Save roger35972134/0b00017eecb38361061e1689f8023b95 to your computer and use it in GitHub Desktop.
Save roger35972134/0b00017eecb38361061e1689f8023b95 to your computer and use it in GitHub Desktop.
Leetcode 3. Longest Substring Without Repeating Characters, but it failed by Submission Result: Time Limit Exceeded
# @param {String} s
# @return {Integer}
# ----------time limit-------------
def length_of_longest_substring(s)
longest_length = 0
for i in 0..s.length-1
check = []
for j in i..s.length-1
unless check.include? s[j]
check.push s[j]
else
break
end
end
if check.size > longest_length
longest_length = check.size
index = i
end
end
longest_length
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment