Skip to content

Commit 3dc9984

Browse files
committed
3
1 parent 4a59b8d commit 3dc9984

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def length_of_longest_substring(s)
2+
return 1 if s.length == 1
3+
return 0 if s.length.zero?
4+
5+
window = []
6+
appear = {}
7+
max = 0
8+
s.each_char do |c|
9+
if appear.key?(c)
10+
while appear.key?(c)
11+
appear.delete(window.shift)
12+
end
13+
end
14+
window << c
15+
appear[c] = c
16+
max = window.length if window.length > max
17+
end
18+
max
19+
end

0 commit comments

Comments
 (0)