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. 常用的7个SQl优化技巧

    作为程序员经常和数据库打交道的时候还是非常频繁的,掌握住一些Sql的优化技巧还是非常有必要的.下面列出一些常用的SQl优化技巧,感兴趣的朋友可以了解一下. 1.注意通配符中Like的使用 以下写法会造 ...

  2. c# 检查目录,当指定目录不存在时建立目录

    /// <remark> /// 检查目录,当指定目录不存在时建立目录 /// </remark> public static void CheckFolder(string ...

  3. 撩课-Web大前端每天5道面试题-Day34

    1.React 中 keys 的作用是什么? Keys 是 React 用于追踪哪些列表中元素被修改.被添加或者被移除的辅助标识. render () { return ( <ul> {t ...

  4. Gson 使用和原理

    使用教程: http://blog.csdn.net/axuanqq/article/details/51441590 http://www.jianshu.com/p/fc5c9cdf3aab 源码 ...

  5. 使用cgroup进行系统资源使用限制

    环境:Centos 7 64 一.对某个进程限制它使用cpu为50% 1.先写一个占用cpu较高的脚本 x=0 while [ True ];do x=$x+1 done; 2.可以看到运行后cpu使 ...

  6. npm包管理工具在一般项目中的应用方法

    最近自己在有时间,在通学一些知识点,记录一下,以便以后使用方面 当我们在做项目的时候,如果需要到包管理工具,那么我们一定会经历以下流程: 1.首先在官网下载node.js,然后默认安装到C盘 检查是否 ...

  7. js-ES6学习笔记-Class(2)

    1.与函数一样,类也可以使用表达式的形式定义. const MyClass = class Me { getClassName() { return Me.name; } }; 这个类的名字是MyCl ...

  8. HTML(5)基础

    1.html常用标签 <pre>...</pre>:标识预定义文本 <a>是anchor的缩写,<a>标签定义锚点和超链接,<a>常与hre ...

  9. page、request、session和application有什么区别?

    转自:http://liuyuru.iteye.com/blog/773367 1.简单说 page指当前页面.在一个jsp页面里有效 2.request 指从http请求到服务器处理结束,返回响应的 ...

  10. ss 重新设置 端口的方法 记录

    1. 选择 ssh 进行远程登入: ssh root@服务器ip -p 端口, 事例如:ssh root@176.122.134.96 -p 28202 2. ls 展示 当前目录下的文件,看到有 s ...