方法一:hashSet
class Solution { public int lengthOfLongestSubstring(String s) { if(s==null||s.length()==0){ return 0; } Set<Character> set=new HashSet<>(); int max=0; int current=0; for(int i=0;i<s.lenght();i++){ while(current<=i&&!set.containsKey(s.charAt(i))){ set. current++; } } } }