leetcode-3. Longest Substring Without Repeating Characters

来源:互联网 发布:日本好用护肤品知乎 编辑:程序博客网 时间:2024/06/05 07:27

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

代码如下:

public class Solution {    public int lengthOfLongestSubstring(String s) {        Set<Character> set=new HashSet<>();        int max=0,j=0,i=0;        while(j<s.length())        {            if(!set.contains(s.charAt(j)))            {                set.add(s.charAt(j++));               // j++;                max=Math.max(max,set.size());            }else            {                //j++;                set.remove(s.charAt(i++));            }        }    return max;    }}
阅读全文
0 0
原创粉丝点击