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. VC++共享文件夹

    BOOL NetShare(char * pShareName,char * pSharePath) { USES_CONVERSION; SHARE_INFO_502 si502; NET_API_ ...

  2. FAQrobot 聊天机器人笔记

    follow: https://github.com/ofooo/FAQrobot  这是一个简单的基于问词匹配的自动问答,获取与用户问句Q1最匹配的知识库中的问句Q2,Q2的答案就是Q1的答案. 首 ...

  3. CodeForces - 1000D:Yet Another Problem On a Subsequence (DP+组合数)

    The sequence of integers a1,a2,…,aka1,a2,…,ak is called a good array if a1=k−1a1=k−1 and a1>0a1&g ...

  4. Win 10 无法打开内核设备“\\.\Global\vmx86”

    Win 10操作系统, VMWareWorkstation10 无法打开内核设备“\\.\Global\vmx86”: 系统找不到指定的文件.你想要在安装 VMware Workstation 前重启 ...

  5. 【Lintcode】136.Palindrome Partitioning

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  6. 【Lintcode】122.Largest Rectangle in Histogram

    题目: Given n non-negative integers representing the histogram's bar height where the width of each ba ...

  7. C++ STL std::wstring_convert处理UTF8

    #include <iostream> #include <string> #include <locale> #include <codecvt> # ...

  8. c# Linq Where 抛出异常 导致 程序崩溃

    Collection was modified; enumeration operation may not execute" 这次项目中遇到一个问题, 就是C#程序随机崩溃, 抛出上面的异 ...

  9. valgrind 代码检查,内存泄漏

    使用平台 linux 下载 http://valgrind.org/ 文档 http://valgrind.org/docs/manual/manual.html 博客 https://www.osc ...

  10. Eclipse&nbsp;Helios(3.6.2)下载地址

    Eclipse Helios(3.6.2)下载地址   鉴于有些插件最高只能支持到指定的eclipse 3.6版本,以此收集3.6下载地址 Eclipse Helios (v3.6.2) Eclips ...