public static int lengthOfLongestSubstring(String s) {
// write code here
int maxSize = 0;
char[] characters = s.toCharArray();
List<Character> list1 = new ArrayList<>();
List<Character> list2 = new ArrayList<>();
for (int i = 0; i < characters.length; i++) {
if (list1.contains(characters[i])) {
int pos = list1.indexOf(characters[i]);
if (list1.size() > maxSize) {
maxSize = list1.size();
}
list2.clear();
for (int i1 = pos+1; i1 < list1.size(); i1++) {
list2.add(list1.get(i1));
}
list1.clear();
for (int i1 = 0; i1 < list2.size(); i1++) {
list1.add(list2.get(i1));
}
}
list1.add(characters[i]);
}
return maxSize;
}