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. ES6 Map数据结构

    Map JavaScript 的对象(Object),本质上是键值对的集合(Hash 结构),但是传统上只能用字符串当作键.这给它的使用带来了很大的限制. ES6 提供了 Map 数据结构.它类似于对 ...

  2. 我所理解的RESTful Web API [Web标准篇]【转】

    原文:http://www.cnblogs.com/artech/p/restful-web-api-01.html REST不是一个标准,而是一种软件应用架构风格.基于SOAP的Web服务采用RPC ...

  3. julia

    版本还不成熟,等成熟了再完整的看看吧.

  4. 【Shell】变量的取用、删除、取代与替换

    ——来自<鸟哥的Linux私房菜> ——总结做方便查阅之用 变量的取用: echo echo $variableecho $PATHecho ${PATH} 变量的配置守则1.变量与变量内 ...

  5. CentOS 6以下版本 支持Ext4

    CentOS默认是不支持Ext4.所以你需要处理一下才行. 使用环境使用的是CentOS5.8 内核是  2.6.18-238.19.1.el5 其实CentOS 5.8 里面是有 ext4 模块的, ...

  6. SqL注入攻击实践

    研究缓冲区溢出的原理,至少针对两种数据库进行差异化研究 缓冲区溢出原理 缓冲区溢出是指当计算机程序向缓冲区内填充的数据位数超过了缓冲区本身的容量.溢出的数据覆盖在合法数据上.理想情况是,程序检查数据长 ...

  7. mongdb启动问题

    问题:Detected unclean shutdown - /data/db/mongod.lock is not empty. old lock file:/data/db/mongod.lock ...

  8. [转]深入了解 CSS3 新特性

    简介 CSS 即层叠样式表(Cascading Stylesheet).Web 开发中采用 CSS 技术,可以有效地控制页面的布局.字体.颜色.背景和其它效果.只需要一些简单的修改,就可以改变网页的外 ...

  9. python optparse命令解析模块

    来源:http://www.cnblogs.com/pping/p/3989098.html?utm_source=tuicool&utm_medium=referral 来源:http:// ...

  10. Nuget:RQCode

    ylbtech-Nuget:QRCode 1.返回顶部 1. https://www.nuget.org/packages?q=qrcode 2. 2.qrcode.js返回顶部 1. https:/ ...