mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update and rename str-longest-non-repeating.py to longest_non_repeating.py
This commit is contained in:
parent
e54535ae2b
commit
b9b5d8e21c
@ -2,21 +2,16 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# author: bt3gl
|
# author: bt3gl
|
||||||
|
|
||||||
# find the length of the longest substring without repeating characters
|
|
||||||
|
|
||||||
|
def length_longest_substring(s) -> int:
|
||||||
def length_longest_substring(s: str) -> int:
|
|
||||||
|
|
||||||
result = ""
|
result = ""
|
||||||
this_longest_string = ""
|
this_longest_string = ""
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
for c in s:
|
for c in s:
|
||||||
|
|
||||||
j = 0
|
j = 0
|
||||||
|
|
||||||
# this loop breaks if repeated
|
|
||||||
while j < len(this_longest_string):
|
while j < len(this_longest_string):
|
||||||
|
|
||||||
if c == this_longest_string[j]:
|
if c == this_longest_string[j]:
|
||||||
@ -26,17 +21,7 @@ def length_longest_substring(s: str) -> int:
|
|||||||
|
|
||||||
j += 1
|
j += 1
|
||||||
|
|
||||||
# this loop continues creating the string
|
|
||||||
this_longest_string += c
|
this_longest_string += c
|
||||||
|
|
||||||
|
|
||||||
return result, this_longest_string
|
return result, this_longest_string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
s = "abcabcbb"
|
|
||||||
print(length_longest_substring(s))
|
|
||||||
|
|
||||||
s = "dvdf"
|
|
||||||
print(length_longest_substring(s))
|
|
Loading…
x
Reference in New Issue
Block a user