LeetCode Longest Substring Without Repeating Characters

来源:互联网 发布:淘宝店铺所在地修改 编辑:程序博客网 时间:2024/06/04 20:04

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

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



0 0
原创粉丝点击