Longest Substring Without Repeating Characters

https://leetcode.com/problems/longest-substring-without-repeating-characters/

class Solution {
    public int lengthOfLongestSubstring(String s) {
         int len = 0;
        if(s==null || s.length()==0){
            len = 0;
        }else{
            for(int i = 0;i < s.length();i++) {
                Map mapDict = new HashMap();
                int temp = 0;
                for (int j = i; j < s.length(); j++) {
                    if (!mapDict.containsKey(s.charAt(j))) {
                        mapDict.put(s.charAt(j),s.charAt(j));
                        temp++;
                    }else{
                        break;
                    }
                }
                if (temp > len) {
                    len = temp;
                }
            }
        }
        return len;      
    }
}

你可能感兴趣的:(LeetCode)