Longest Substring Without Repeating Characters

Jun 11, 2016


```python

#!/usr/bin/env python

coding=utf-8

def long_sub(s): ret=0 tmp=”” tmpLen=0 for v in s: if v in tmp: if tmpLen > ret: ret = tmpLen tmp = tmp[tmp.index(v)+1:] + v tmpLen=len(tmp) else: tmp += v tmpLen += 1

if tmpLen > ret:
    ret=tmpLen
return ret

long_sub(‘dvdf’) long_sub(‘abcabcbb’) long_sub(‘bbbbb’) long_sub(‘pwwkew’)