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 思 ...
随机推荐
- 并行计算:并行I/O服务器的操作参数
视频来源:新竹清华大学:并行计算与并行编程课程 上图结论:随着年限,计算力的增长很快,而I/O近于平缓,二者之间的差距增大,带来不利的影响.需要一些方法来处理这较大的差距. 解决方案: 1:I/O 内 ...
- 安装Rtools
1.好多工具需要安装Rtools install.packages("installr") install.packages("stringr") ###依赖包 ...
- c语言新知
C语言学得有点懈怠,昨个遇一个高手. 教了我两天,真细腻. 第一天,让我写一个程序删除字符串多余空格. 我俩代码对比 结果很显然了.
- 【转】struts2的ActionInvocation分析(action调度者)
一个ActionInvocation实例代表一个action的执行状态,持有拦截器和将要执行的action的实例. defaultActionInvocation是其默认实现.下面是定义在该类中的部分 ...
- 安卓模拟器可访问电脑ip配置
开发的时候,发现安卓模拟器没办法访问调用开发的接口,因为安卓模拟器没有绑定配置hosts,所以需要在模拟器上配置hosts 首先配置环境变量,用户变量的path和系统变量 我的路径 C:\Users\ ...
- ZooKeeper 入门看这篇就够了
什么是 ZooKeeper? ZooKeeper 是一个分布式的,开放源码的分布式应用程序协同服务.ZooKeeper 的设计目标是将那些复杂且容易出错的分布式一致性服务封装起来,构成一个高效可靠的原 ...
- 快速认识springcloud微服务
这周浅显的学习了springcloud.简单聊一下微服务.所谓的微服务远远没有我想想的那么高端难以理解,简单说,就是多个服务分布在不同的服务器上,由这些服务互相配合完成某一项任务.那服务和服务之间调用 ...
- .NET Core 多框架支持(net45+netstandard20)实践中遇到的一些问题总结
.NET Core 多框架支持(net45+netstandard20)实践中遇到的一些问题总结 前言 本文主要是关于.NET Standard 代码 在多框架 和 多平台 支持自己实践过程中遇到的一 ...
- Kubernetes service 使用定义
Kubernetes service 使用定义 介绍说明 • 防止Pod失联• 定义一组Pod的访问策略• 支持ClusterIP,NodePort以及LoadBalancer三种类型• Servic ...
- .NET WebFrom跨时区项目时间问题处理方法
前段时间因为公司的一个 WebFrom 项目设计到跨时区的问题,处理了一段时间,终于解决了,写个博客记录一下,方便以后回顾以及给他人提供一个参考的方法. 本次的项目因为跨越了多个时区,在一些时间上会受 ...