# 问题描述

Given a string, find the length of thelongest substringwithout repeating characters.

Examples:

Given`"abcabcbb"`, the answer is`"abc"`, which the length is 3.

Given`"bbbbb"`, the answer is`"b"`, with the length of 1.

Given`"pwwkew"`, the answer is`"wke"`, with the length of 3. Note that the answer must be asubstring,`"pwke"`is asubsequenceand not a substring.

# Java

`public class Solution {    public int lengthOfLongestSubstring(String s) {       int maxLength = 0;        if (s.length() == 0 || s.length() == 1) return s.length();        for (int i = 0; i < s.length(); i++) {            Map<Character, Integer> visit = new HashMap<>();            visit.put(s.charAt(i), 1);            for (int j = i + 1; j < s.length(); j++) {                if (visit.containsKey(s.charAt(j))) {                    if (j - i > maxLength) {                        maxLength = j - i;                    }                    break;                } else if (j - i + 1 > maxLength) {                    maxLength = j - i + 1;                }                visit.put(s.charAt(j), 1);            }        }        return maxLength;    }}`