public int lengthOfLongestSubstring(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }

        int max = 1;

        int currentStart = 0;
        int currentLength = 0;
        HashMap<Character, Integer> sequence = new HashMap<Character, Integer>();
        for (int i = 0; i < s.length(); i++) {
            char currentChar = s.charAt(i);
            if (sequence.containsKey(currentChar)) {
                int index = sequence.get(currentChar);

                if (index >= currentStart) {
                    currentStart = index + 1;
                    if (max < currentLength) {
                        max = currentLength;
                    }
                    currentLength = i - currentStart + 1;
                } else {
                    currentLength++;
                }
            } else {
                currentLength++;
            }
            sequence.put(currentChar, i);
        }
        return max > currentLength ? max: currentLength;
    }