public class Solution {
public int LengthOfLongestSubstring(string s) {
int max = 0;
if(string.IsNullOrEmpty(s)){
return 0;
}
for(int i = 0 ; i < s.Length; i++){
Dictionary<char, int> cache = new Dictionary<char, int>();
for(int j = i; j < s.Length; j++){
if(cache.ContainsKey(s[j])){
i = cache[s[j]]; //jump
break;
}
else{
cache.Add(s[j], j);
max = Math.Max(max, cache.Count);
}
}
}
return max;
}
}