Skip to content

Commit

Permalink
Create Substring-without-repeat.py
Browse files Browse the repository at this point in the history
Finds the longest substring without repeating characters in a string
  • Loading branch information
gabedonnan authored Jan 12, 2023
1 parent acd241e commit d8582e9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Substring-without-repeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
seen = ""
current_len = 0
longest = 0
start = 0
flag = False
ind = 0
while ind < len(s):
if s[ind] in seen:
seen = ""
if current_len > longest:
longest = current_len
current_len = 0
start += 1
ind = start
flag = True


if not flag:
current_len += 1
seen += s[ind]
ind += 1
flag = False
return max(longest, current_len)


0 comments on commit d8582e9

Please sign in to comment.