fork(2) download
  1. def lenLongestSubstring( stringX ):
  2. maxi = 0
  3. trackList = [] # List to store the chars that have been visited
  4. for char in stringX :
  5. if ( char not in trackList ):
  6. trackList.append(char)
  7. else: # found a repeating char
  8. listLen = len(trackList)
  9. maxi = max( maxi, listLen )
  10. trackList[:] = [char] # clears the list
  11. return max( maxi, len(trackList) )
  12.  
  13.  
  14. def main():
  15. print lenLongestSubstring("abcadeftgh")
  16. print "\nAll asserts PASSED!!, Yaaaaaay!!\n"
  17.  
  18. if __name__ == "__main__":
  19. main()
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
7

All asserts PASSED!!, Yaaaaaay!!