Created
October 11, 2017 06:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @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