参考思路

https://github.com/azl397985856/leetcode/blob/master/problems/3.longestSubstringWithoutRepeatingCharacters.md

public int lengthOfLongestSubstring(String s) {
HashMap<Character, Integer> repeatChar = new HashMap<>();
int left = 0;
char c;
int maxLength = 0;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if (!repeatChar.containsKey(c) || (i < left)) {
repeatChar.put(c, i);
continue;
}
maxLength = Math.max(maxLength,i-left);
left = Math.max(left,repeatChar.get(c)+1);//有时候重复的在最
repeatChar.put(c,i);
}
maxLength = Math.max(maxLength,s.length() - left);
return maxLength; }

  

LeetCode3-Longest_Substring_Without_Repeating_Characters的更多相关文章

  1. Leetcode3:Longest Substring Without Repeating Characters@Python

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

  2. LeetCode3:Longest Substring Without Repeating Characters

    题目: Given a string, find the length of the longest substring without repeating characters. For examp ...

  3. LeetCode----3 Sum

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  4. leetcode3:不重复的最长子串长度

    package hashmap; import java.util.HashMap; import java.util.Map; public class hashmap { public stati ...

  5. LeetCode3 Longest Substring Without Repeating Characters

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

  6. leetcode3 Two Sum III – Data structure design

    Question: Design and implement a TwoSum class. It should support the following operations: add and f ...

  7. [Swift]LeetCode3. 无重复字符的最长子串 | Longest Substring Without Repeating Characters

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

  8. leetcode3

    public class Solution { public int LengthOfLongestSubstring(string s) { var dic = new Dictionary< ...

  9. leetcode3:无重复字符的最长子串

    给定一个字符串,找出不含有重复字符的最长子串的长度. 示例: 给定 "abcabcbb" ,没有重复字符的最长子串是 "abc" ,那么长度就是3. 给定 &q ...

  10. leetcode-[3]Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line 思 ...

随机推荐

  1. 【Excel】创建目录

    1.=INDEX(GET.WORKBOOK(1),ROW(A1))&T(NOW()) 2. =IFERROR(HYPERLINK(我的目录&"!A1",MID(我的 ...

  2. 开源项目 13 log4net

    原文:https://www.cnblogs.com/pudefu/p/9300697.html 官方的api: http://logging.apache.org/log4net/release/s ...

  3. bioawk

    https://github.com/lh3/bioawk 1.基本思想 使用: usage: bioawk [-F fs] [-v var=value] [-c fmt] [-tH] [-f pro ...

  4. 水平划分table

    大概10年前,接到的任务是要解决一个AuditTrail表的写入性能. performance test的时候,一晚上这个表可以长1百万行,在SQLServer归档到本地文件以后再去删除这1百万条记录 ...

  5. MySQL实战45讲学习笔记:第三十三讲

    一.引子 我经常会被问到这样一个问题:我的主机内存只有 100G,现在要对一个 200G 的大表做全表扫描,会不会把数据库主机的内存用光了? 这个问题确实值得担心,被系统 OOM(out of mem ...

  6. IOI游记

    你竟然点进来了?那你的脑袋可能和我的一样智障QAQ. 啥也没有,闲的没事挖的坑,不要在意,没啥可读的. 权当是一个目标吧(尽管几乎不可能成真),倘若未来(无数年后),我真的站在IOI的赛场上,那我可以 ...

  7. Eureka注册中心的自我保护模式

    如果在Eureka Server的首页看到以下这段提示,则说明Eureka已经进入了保护模式. EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTAN ...

  8. 大话设计模式Python实现-状态模式

    状态模式(State Pattern):当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类 下面是一个状态模式的demo: #!/usr/bin/env python # -*- ...

  9. Winform的控件以及DataGridView的一般使用

    先上学习测试的一些截图 1:获取多个控件上面的值(checkbox,combobox,textbox,radiobutton) 2:获取到选择行的主键ID的value,方便我们进一步CURD 3:获取 ...

  10. The underlying connection was closed: An unexpected error occurred on a send

    操作系统是Windows Server 2003 x64 SP2,使用Framework 4.0,在使用WebClient访问某些特定的HTTPS站点时,会引发异常: Unhandled Except ...