您的位置:首页 > 其它

leetcode-3. Longest Substring Without Repeating Characters

2017-06-02 21:55 477 查看
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode