题目
解法
①字符串, 哈希表 + 循环
class Solution {
public int lengthOfLongestSubstring(String s) {
Map<Character, Integer> hashmap = new HashMap<Character, Integer>();
int ret = 0;
int start = 0;
int i;
for(i = 0; i < s.length(); i++){
if(hashmap.containsKey(s.charAt(i))){
if(start <= hashmap.get(s.charAt(i))){
ret = Math.max(ret, i - start);
start = hashmap.get(s.charAt(i)) + 1;
}
}
hashmap.put(s.charAt(i), i);
}
ret = Math.max(ret, i - start);
return ret;
}
}