public int lengthOfLongestSubstring(String s) { int max=0; int i=0; int temp=0; char[] array =s.toCharArray(); Map<Character,Integer> hashMap = new HashMap<>(); while(i<array.length){ if (!hashMap.containsKey(array[i])){ hashMap.put(array[i],i); temp++; i++; }else{ temp=0; i=hashMap.get(array[i])+1; hashMap = new HashMap<>(); } max = max>temp?max:temp; } return max; }
无重复字符最长子串
最新推荐文章于 2024-04-23 11:28:18 发布