This took me a bit longer than it probably should have because of subtle issues I didn’t foresee that the test cases definitely test for. All in all though, not too tricky. These harder problems aren’t so bad, really.
Medium
class Solution {
public int lengthOfLongestSubstring(String s) {
List<Character> acc = new ArrayList<>();
int longest = 0;
for (char x : s.toCharArray()) {
if (acc.contains(x)) {
acc = acc.subList(acc.indexOf(x) + 1, acc.size());
}
acc.add(x);
if (acc.size() > longest) {
longest = acc.size();
}
}
return longest;
}
}