idea:

设置一个hashset存储非重复元素

j:遍历s

i:最近的一个非重复指针

注意点:

1.Set set = new HashSet<>();

2. add remove

public int lengthOfLongestSubstring(String s) {
int i = 0, j = 0, max = 0;
Set<Character> set = new HashSet<>(); while(j < s.length()){
if(! set.contains(s.charAt(j)) ){
set.add(s.charAt(j++));
max = Math.max(max, set.size());
}else{
set.remove(s.charAt(i++));
}
}
return max;
}

leetcode 3. Longest Substring Without Repeating Characters [java]的更多相关文章

  1. C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告

    Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...

  2. 【JAVA、C++】LeetCode 003 Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  3. Java [leetcode 3] Longest Substring Without Repeating Characters

    问题描述: Given a string, find the length of the longest substring without repeating characters. For exa ...

  4. leetcode第三题Longest Substring Without Repeating Characters java

    Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...

  5. [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  6. LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)

    题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...

  7. LeetCode 3 Longest Substring Without Repeating Characters 解题报告

    LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...

  8. leetcode:Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  9. [LeetCode][Python]Longest Substring Without Repeating Characters

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

随机推荐

  1. C字符串

    C字符串 C中的字符串是以空字符('\0')结尾的一个char数组,基本的实现字符串的方法有:字符串常量,字符串数组,char数组,char指针.字符串使用广泛,如与用户交互等处理自然语言的情况.C为 ...

  2. Re:从零开始的Spring Session(二)

    上一篇文章介绍了一些Session和Cookie的基础知识,这篇文章开始正式介绍Spring Session是如何对传统的Session进行改造的.官网这么介绍Spring Session: Spri ...

  3. Html.DropDownListFor练习

    今天练习Html.DropDownListFor(). 在网页开发过程中,这个DropDownList功能定会少不了.让用户能显式选择需求的选项.先来看看下面实时操作,Category这个字段是一个外 ...

  4. Mac下,(OS系统)IDEA 逆向工程,生成 hibernate 映射文件以及对应的javaBean(类似于eclipse)

    找了好久,逆向工程生成javabean的,在Macbook的OS系统下使用idea生成. 参考博客:http://m.blog.csdn.net/quan20111992/article/detail ...

  5. Java - 线程Join与interrupt

    Java多线程系列--“基础篇”08之 join() 概要 本章,会对Thread中join()方法进行介绍.涉及到的内容包括:1. join()介绍2. join()源码分析(基于JDK1.7.0_ ...

  6. Outlook2013怎样自动答复电子邮件

    工具/原料 office2013或outlook2013 百度经验:jingyan.baidu.com 方法/步骤 1 首先我们创建自己的答复邮件.打开outlook2013,单击“开始”>“新 ...

  7. python-解释器模式

    源码地址:https://github.com/weilanhanf/PythonDesignPatterns 说明: 解释器模式在面向对象语言实现的编译器中得到了广泛的应用.但是此模式进适用于建大的 ...

  8. apicloud 消息推送与接收

    待解决的问题,如下: 在使用apicloud 的时候我们,在开发用户登录的时候可能会遇到这样的问题,当有2个设备a,b同事使用的app的时候并且是同一个人登录,我们需要去做判断,即大家常说的单点登录. ...

  9. 【读书笔记】iOS-应用程序剖析

    一,Default.png 包含应用程序默认扉页的PNG图像文件.用户运行应用程序时,iPhone会用此图片显示一个动画,产生由小变大来到屏幕前的效果.应用程序的Default.png文件加载后会不断 ...

  10. Tronado自定义Session

    这里就不一一诉说Session和Cookie直接的关系了,下面以一张图来概括: 下面是一个简单的Tornaod自定义Session的例子,看完后你可能会明白为什么我们在Django里可以直接使用req ...