暴力方式
class Solution {
public int lengthOfLongestSubstring(String s) {
Map<Character,Integer> map=new HashMap<>();
int maxLength=0;
int tmpLength=0;
char[] list=s.toCharArray();
for(int i=0;i<list.length;i++){
if(map.get(list[i])==null){
tmpLength++;
map.put(list[i],i);
}else{
i=map.get(list[i]);
map.clear();
tmpLength=0;
}
if(tmpLength>maxLength)
maxLength=tmpLength;
}
return maxLength;
}
}
佛系学习