public static int lengthOfLongestSubstring(String s) {
int max = 0, num = 0;
char[] chs =s.toCharArray();
List<Character> temp = new ArrayList<>();
for (int i = 0; i < chs.length; i++) {
int index = temp.indexOf(chs[i]);
if (index>=0) {
num = temp.size()-index;
temp=temp.subList(index+1,temp.size());
} else {
num++;
}
temp.add(chs[i]);
max = Math.max(num, max);
}
return max;
}