Java solution WITHOUT hashmap
The idea is pretty simple. We iterate thru the list once and we keep a pointer of where the current longest possible substring starts. During the iteration, we 
The idea is pretty simple. We iterate thru the list once and we keep a pointer of where the current longest possible substring starts. During the iteration, we check if this last character is contained in the current substring. If so, move the ptr to the first index of the char at the string +1. Everytime we will compare and keep the max value up to date.\n\nI am calling the indexOf() method for strings which can theoretically be O(N). I am guessing this is cheaper than creating a hashmap for this set of test cases? Anyway, I just want to share my alternative solution:\n\n    public class Solution {\n        public int lengthOfLongestSubstring(String s) {\n            if (s.length() <= 1) return s.length();\n            \n            int max = 1;\n            int ptr = 0;\n            for (int i = 1; i< s.length(); i++) {\n                // find the first occurence of the char after index ptr\n                int index = s.indexOf(s.charAt(i), ptr); \n                if (index < i) { // it means that it is contained in s.substring(ptr, i)\n                    ptr = index + 1;\n                }\n                max = Math.max(max, i - ptr + 1);\n            }\n            \n            return max;\n        }\n    }
['Java']