找到字符串的最长无重复子串
找到字符串的最长无重复字符子串
https://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4?tpId=196&&tqId=37149&rp=1&ru=/ta/job-code-total&qru=/ta/job-code-total/question-ranking
public int maxLength (int[] arr) {
// write code here
if(arr==null) return 0;
Map<Integer,Integer> map=new HashMap<>();
int res = -1;
int start=0;//重复位置的下一个位置
for(int i=0;i<arr.length;i++){
if(map.containsKey(arr[i])){
//当有重复的时候,需要更新start的位置,可能比当前重复的位置远也可能近
start=Math.max(start,map.get(arr[i])+1);
}
//每遍历一次 就更新一次最值
res=Math.max(res,i-start+1);
map.put(arr[i],i);
}
return res;
}
