public int lengthOfLongestSubstring(String s) {
// Start typing your Java solution below
// DO NOT write main() function
HashSet set = new HashSet();
String ret = new String();
int i=0,j=0;
for(i=0;i
set.add(s.charAt(i));
for(j=i+1;j
set.clear();
break;
}
else{
set.add(s.charAt(j));
}
}
if (j - i + 1 > ret.length()) ret = s.substring(i,j);
}
return ret.length();
}
}
没有评论:
发表评论