mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
28 lines
693 B
Python
28 lines
693 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
def length_longest_substring(s) -> int:
|
|
|
|
result = ""
|
|
this_longest_string = ""
|
|
i = 0
|
|
|
|
for c in s:
|
|
j = 0
|
|
|
|
while j < len(this_longest_string):
|
|
|
|
if c == this_longest_string[j]:
|
|
if len(this_longest_string) > len(result):
|
|
result = this_longest_string
|
|
this_longest_string = this_longest_string[j+1:]
|
|
|
|
j += 1
|
|
|
|
this_longest_string += c
|
|
|
|
return result, this_longest_string
|
|
|