Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

longest substring without repeating characters python

str = "AABBCDEFABC"		#string to check
i =0
j = 0
d={}					
sub_str_len = 0
while j < len(str):	#checks every character of the string
  if str[j] not in d or i>d[str[j]]:
    sub_str_len = max(sub_str_len,(j-i+1))
    d[str[j]] = j
  else:
    i = d[str[j]]+1
    sub_str_len = max(sub_str_len,(j-i+1))
    j-=1

  j+=1
    
print(sub_str_len)		#prints the size
    
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #longest #substring #repeating #characters #python
ADD COMMENT
Topic
Name
2+5 =