Skip to content

Instantly share code, notes, and snippets.

@roger35972134
Created October 11, 2017 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roger35972134/7a6f81c784fc5e11c1a10a19aa41f2a2 to your computer and use it in GitHub Desktop.
Save roger35972134/7a6f81c784fc5e11c1a10a19aa41f2a2 to your computer and use it in GitHub Desktop.
# @param {String} s
# @return {Integer}
def length_of_longest_substring(s)
max = 0
for i in 0..s.length-1
check = Array.new(256, false)
for j in i..s.length-1
index = s[j].ord
if check[index] == false
check[index] = true
else
break
end
end
if check.count(true) > max
max = check.count(true)
end
end
max
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment