参考思路

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. ionic4之ion-sliders

    <ion-content class="details_"> <img class="courimg_" src="assets/i ...

  2. Apache 监听 ipv4

    查看端口信息 ifconfig 发现只有 ipv6 的 80 端口被监听,ipv4 的 80 端口没有被监听 因此通过 ipv4 无法访问 tcp6 0 0 :::80 :::* LISTEN 221 ...

  3. Jike_Time-决策树

    根节点 非叶子节点(决策点) 叶子节点(决策结果) 分支 熵代表混乱程度 信息增益 构造树的基本想法是随着树深度的增加.节点的熵迅速地降低.熵降低的速度越快越好,这样我们有望得到一颗高度最矮的决策树 ...

  4. T-SQL 简介

    1. 变量说明语句:用来说明变量的命令. 2. 数据定义语言(Data Definition Language,DDL):用来建立数据库和定义列等数据结构,主要是create table,drop d ...

  5. Flume笔记

    flume自定义拦截器:实现Interceptor接口flume自定义source:继承AbstractSourceflume自定义sink:继承AbstractSink azkaban:任务调度工具 ...

  6. 阿里云容器服务中国最佳,进入 Forrester 报告强劲表现者象限

    近日,全球知名市场调研机构 Forrester 发布首个企业级公共云容器平台报告. 报告显示:阿里云容器服务创造了中国企业最好成绩,与谷歌云位于同一水平线,进入强劲表现者象限. 究其原因,分析师认为: ...

  7. 【04】Nginx:rewrite / if / return / set 和变量

    写在前面的话 我们前面已经谈了编译安装,基本语法,日志处理,location 匹配,root / alias 的不同效果.这里我们主要谈谈 rewrite(重写)功能,顺便说说 nginx 中自带的变 ...

  8. [Flutter] Windows桌面程序开发

    在今年5月的谷歌I/O 2019大会时, 谷歌就宣布了flutter已经支持全平台开发, 包括 android, ios, mac, linux, windows, web 等 . Flutter桌面 ...

  9. Winform 美化

    首先,我们先来实现主界面的扁平化 此处分为两个步骤,第一步是更改winform自带的MainForm窗体属性,第二步是添加窗体事件. 将主窗体FormBorderStyle更改为None,这样就得到了 ...

  10. Python - 获取本机IP地址、Mac地址

    Python - 获取本机IP地址.Mac地址 在python中获取ip地址和在php中有很大不同,在php中往往比较简单.那再python中怎么做呢? 直接看代码: # Python - 获取本机I ...