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

public class Solution {
    public int lengthOfLongestSubstring(String s) {

        if(s.length() == 0 )return 0;
        HashMap<Character,Integer> map = new HashMap<Character, Integer>();
        int max = 0;
        int j = 0;
        for(int i=0;i<s.length();i++){
            if(map.containsKey(s.charAt(i))){
                j=Math.max(j,map.get(s.charAt(i))+1);
            }
            map.put(s.charAt(i),i);
            max = Math.max(max,i-j+1);
        }
        return max;
        
    }
}

相关文章:

  • 2021-10-04
  • 2021-08-01
  • 2022-02-13
  • 2021-08-03
  • 2022-01-06
猜你喜欢
  • 2021-12-22
  • 2021-11-06
  • 2022-12-23
  • 2021-09-13
  • 2021-09-11
  • 2021-08-28
相关资源
相似解决方案