参考思路

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. 002Excel冻结窗口(冻结第二行)

    不知道是最近状态不好还是怎么回事Excel冻结前面两行居然弄了很久,而工作上又急需,为此还是记录一下 其实超级简单(不会的话就很难) 如果冻结一行 这个非常简单 那么冻结前面两行呢?我研究了很久,其实 ...

  2. 小白专场-是否同一颗二叉搜索树-c语言实现

    目录 一.题意理解 二.求解思路 三.搜索树表示 程序框架搭建 3.1 如何建搜索树 3.2 如何判别 3.3 清空树 更新.更全的<数据结构与算法>的更新网站,更有python.go.人 ...

  3. 第09组 Beta版本演示

    组长博客 本组(组名)所有成员 短学号 姓名 2236 王耀鑫(组长) 2210 陈超颖 2209 陈湘怡 2228 许培荣 2204 滕佳 2205 何佳琳 2237 沈梓耀 2233 陈志荣 22 ...

  4. 纯CSS打造BiliBili样式博客主题

    前言 一直以来,我都在思考如何减少不必要的JS代码,仅通过CSS来实现博客园主题美化.CSS有很多魔法代码,例如:before,iconfont,order,等等,利用好这些技巧,也能实现很好美化效果 ...

  5. 多台Linux 7.x服务器具有相同的UUID网络链接参数,肿么办?

    1.查看多台服务器的UUID网络链接参数是否相同 我这里使用SecureCRT的全部交互功能,直接批量输出  /etc/sysconfig/network-scripts/ifcfg-ens33 的内 ...

  6. windows server 2008配置多用户远程连接

    打开开始菜单->管理工具->远程桌面服务->远程桌面会话主机配置 右键限制每个用户只能进行一个会话->常规->勾掉限制每个与用户只能进行一个会话 右键远程桌面授权模式-& ...

  7. 在Anaconda中使用linux的命令

    在Anaconda中使用linux的命令 1.在anaconda中执行以下命令即可(要先activation 想用的环境): conda install m2-base 2.安装git.添加环境变量即 ...

  8. vue v-html 富文本解析 空格,换行,图片大小问题

    1.保留空格,换行属性 //保留换行空格问题 white-space: pre-wrap; 2.超出部分,强制换行,一般用于数字 //富文本换行 word-wrap: break-word; tabl ...

  9. Window权限维持(六):BITS Jobs

    Windows操作系统包含各种实用程序,系统管理员可以使用它们来执行各种任务.这些实用程序之一是后台智能传输服务(BITS),它可以促进文件到Web服务器(HTTP)和共享文件夹(SMB)的传输能力. ...

  10. [转载].NET ASP.NET 中web窗体(.aspx)利用ajax实现局部刷新

    之前开发的一套系统中用到了大量的 checkboxList 控件,但是每次选定之后都会刷新整个页面,用户体验很差,百度了之后查到这篇文章,尝试了一下可以实现,所以转载了过来,记录一下,也给其他有相同困 ...