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

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

[Leetcode]003. Longest Substring Without Repeating Characters的更多相关文章

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

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

  2. LeetCode #003# Longest Substring Without Repeating Characters(js描述)

    索引 思路1:分治策略 思路2:Brute Force - O(n^3) 思路3:动态规划? O(n^2)版,错解之一:420 ms O(n^2)版,错解之二:388 ms O(n)版,思路转变: 1 ...

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

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

  4. 【LeetCode】003. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

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

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

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

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

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

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

  8. LeetCode之Longest Substring Without Repeating Characters

    [题目描述] Given a string, find the length of the longest substring without repeating characters. Exampl ...

  9. Leetcode 3. Longest Substring Without Repeating Characters (Medium)

    Description Given a string, find the length of the longest substring without repeating characters. E ...

随机推荐

  1. 时尚设计div+css免费模板

    时尚设计div+css免费网页模板,时尚设计,div+css. http://www.huiyi8.com/moban/

  2. RQNOJ 95 多多看DVD(加强版):01背包

    题目链接:https://www.rqnoj.cn/problem/95 题意: 叔叔要陪多多看动画片. 有n张DVD可以买,第i张碟的打分为w[i],播放时间为t[i]. 爷爷规定他们只能在一定的时 ...

  3. TP框架控制器和对应方法创建

    控制器和对应方法创建 控制器是MVC模式中的核心,TP默认有一个控制器:   Index控制器里面有一个操作方法:Index   我们在访问http://localhost:8080/Thinkphp ...

  4. yii2 linux安装教程

    安装扩展 安装Yii最好的方式就是使用Composer安装,所以我们需要安装Composer,但是为了安装Composer,我们需要安装一下关于Composer和Yii2的许多扩展包,别担心下面的教程 ...

  5. BZOJ - 4518: 征途(斜率优化,求N数划分为M区间的最小方差)

    注意初始化...等等补 #include<bits/stdc++.h> #define ll long long using namespace std; ; int q[maxn],he ...

  6. 「 JSOI2004」「LuoguP1337」平衡点 / 吊打XXX(模拟退火

    题目描述 如图:有n个重物,每个重物系在一条足够长的绳子上.每条绳子自上而下穿过桌面上的洞,然后系在一起.图中X处就是公共的绳结.假设绳子是完全弹性的(不会造成能量损失),桌子足够高(因而重物不会垂到 ...

  7. MOVE降低高水位 HWM

    MOVE降低高水位 HWM --创建实验表空间SQL> create tablespace andy03 datafile '/home/oracle/app/oradata/orcl/andy ...

  8. DTP模型之一:(XA协议之三)MySQL数据库分布式事务XA优缺点与改进方案

    1 MySQL 外部XA分析 1.1 作用分析 MySQL数据库外部XA可以用在分布式数据库代理层,实现对MySQL数据库的分布式事务支持,例如开源的代理工具:ameoba[4],网易的DDB,淘宝的 ...

  9. shader之texture

    纹理坐标作为属性传递到顶点着色器 texture是OPENGL对象,包含一张或多张相同格式的图片. 它有2中用途: the source of a texture access from a Shad ...

  10. 2-1 本章作业&2-2 开发系统与工具选择

    2-1 2-2 推荐使用Android Studio开发Flutter