fork(1) 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 ( not ( char in trackList ) ):
  6. trackList.append(char)
  7. else: # found a repeating char
  8. listLen = len(trackList)
  9. maxi = max( maxi, listLen )
  10. trackList[:] = [] # clears the list
  11. return max( maxi, listLen )
  12.  
  13.  
  14. def main():
  15. assert lenLongestSubstring( "BBBBB" ) == 1
  16. assert lenLongestSubstring( "ABDEFGABEF" ) == 6
  17. assert lenLongestSubstring( "abcabcbb" ) == 3
  18. print "\nAll asserts PASSED!!, Yaaaaaay!!\n"
  19.  
  20. if __name__ == "__main__":
  21. main()
Success #stdin #stdout 0.09s 8912KB
stdin
Standard input is empty
stdout
All asserts PASSED!!, Yaaaaaay!!