LeetCode3-Longest_Substring_Without_Repeating_Characters
参考思路
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的更多相关文章
- Leetcode3:Longest Substring Without Repeating Characters@Python
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- LeetCode3:Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- 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 ...
- leetcode3:不重复的最长子串长度
package hashmap; import java.util.HashMap; import java.util.Map; public class hashmap { public stati ...
- LeetCode3 Longest Substring Without Repeating Characters
题意: Given a string, find the length of the longest substring without repeating characters. Examples: ...
- leetcode3 Two Sum III – Data structure design
Question: Design and implement a TwoSum class. It should support the following operations: add and f ...
- [Swift]LeetCode3. 无重复字符的最长子串 | Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- leetcode3
public class Solution { public int LengthOfLongestSubstring(string s) { var dic = new Dictionary< ...
- leetcode3:无重复字符的最长子串
给定一个字符串,找出不含有重复字符的最长子串的长度. 示例: 给定 "abcabcbb" ,没有重复字符的最长子串是 "abc" ,那么长度就是3. 给定 &q ...
- 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 思 ...
随机推荐
- 使用Qiniu-JavaScript-SDK上传文件至七牛云存储
一.Qiniu-JavaScript-SDK介绍 基于 JS-SDK 可以方便的从浏览器端上传文件至七牛云存储,并对上传成功后的图片进行丰富的数据处理操作. JS-SDK 兼容支持 H5 File A ...
- B1013
python语言运行这道题有一个点运行超时,需要对求素数的算法进一步的优化 def isPrime(n): if n <= 1: return False i = 2 while i * i & ...
- ubuntu16.04下安装nvidia驱动心得
首先机器重启后莫名出现循环登录错误,然后按照网上的方法卸载掉nvidia驱动后,可以正常登录. 但还是要再装nvidia驱动.网上说的各种方法都试过了,geforce.cn官网上推荐的各种版本的run ...
- spring boot 不占用端口方式启动
随着微服务架构的流行,想要启动一个微服务架构项目就要开启好多端口,有时候一台机器上部署的项目多的时候,端口资源就比较紧张了,其实有的微服务组件仅仅只是提供RPC服务,可以不用占用web启动的端口,此时 ...
- python 自定义Iterator对象
from collections.abc import Iterator class Company(object): def __init__(self, employee_list): self. ...
- 关于 C# 8.0 的 Switch Case When 的用法
直接贴代码了: static void Main(string[] args) { SwitchSample(); } private static void SwitchSample() { Swi ...
- My time is limited
Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma - whic ...
- JS读取xml
xml文件 <?xml version="1.0" encoding="utf-8"?> <root> <data id=&quo ...
- springmvc在使用@ModelAttribute注解获取Request和Response会产生线程并发不安全问题(转)
springmvc在获取Request和Response有很多方式:具体请看:https://www.cnblogs.com/wade-luffy/p/8867144.html 产生线程问题的代码如下 ...
- warning: Unexpected unnamed function (func-names)
warning: Unexpected unnamed function (func-names) 看到这个提示基本是就是说你的函数不能是匿名函数,最好可以起一个名字,然后你增加一个函数名称就好了 R ...