- (void)viewDidLoad {
[super viewDidLoad];
NSString *str = @"gasdkgkasgjdnafgdgda";
NSMutableSet*set = [NSMutableSet new];
long n = str.length;
int ans = 0, i = 0, j = 0 ,index = 0;
while (i<n && j<n) {
if (![set containsObject:[str substringWithRange:NSMakeRange(j,1)]]) {
[set addObject:[str substringWithRange:NSMakeRange(j++, 1)]];
if (j - i > ans) {
ans = j - i;
index = i;
}
}else{
[set removeObject:[str substringWithRange:NSMakeRange(i++, 1)]];
}
}
NSLog(@"%@",[str substringWithRange:NSMakeRange(index, ans)]);
}