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 思 ...
随机推荐
- SpringBoot启用https
1.利用JDK自带的keytool生成证书 keytool -genkey -storetype PKCS12 -alias tomcat -keyalg RSA -keysize 2048 -key ...
- 运维相关指标数据采集并ES入仓 - 运维笔记
为了进行数字化IT治理,需要对一些应用进程相关指标进行采集并入库.收集到的应用指标数据最好要进行ES入仓,入到Kafka里面,并通过Kibana可视化展示. 需要进行采集的应用进程相关指标如下: ES ...
- CSS3 滤镜Filter亮度动画
CSS3 滤镜Filter亮度动画 -webkit-filter:brightness 值越高 亮度越亮<pre><!DOCTYPE html><html lang=&q ...
- IEEE 二进制浮点数的表示
朋友在谈一个物流相关的项目,是以前项目的一个延续,涉及到后台的扩展,手机端的App,外加两个App的对接的蓝牙打印机.这个项目前后说了一个多月了吧,最近才草拟了协议.项目本来不复杂,但是客户却如此的拖 ...
- 十二、深入理解Java内存模型
深入理解Java内存模型 [1]CPU和缓存的一致性 我们应该都知道,计算机在执行程序的时候,每条指令都是在CPU中执行的,而执行的时候,又免不了要和数据打交道.而计算机上面的数据,是存放在主存当 ...
- oracle排序子句的特殊写法与ORA-01785错误
刚刚写的SQL语句在执行的时候报[ORA-01785: ORDER BY item must be the number of a SELECT-list expression]错误,于是自己百度了一 ...
- Vertx和Jersey集成使用
为了更好地解耦和提高性能,一般将工程的接口部分剥离出来形成一个单独的工程,这样不仅能提高性能,增强可维护性,并且在后台工程宕掉的话对客户端接口的影响较小. 公司使用了Vertx和Jersey,Vert ...
- easyui datagird 解决行高不一致问题!
<style>.datagrid-btable .datagrid-cell {padding: 6px 4px;overflow: hidden;text-overflow: ellip ...
- CTF挑战赛丨网络内生安全试验场第一季答题赛火热开启
前期回顾:挑战世界级“人机大战”,更有万元奖金等你来拿 网络内生安全试验场自上线以来,受到了业内的极大重视与关注. 自9月2日报名通道开启后,报名量更是持续高升,上百名精英白帽踊跃报名. 至此,网络内 ...
- Linux 和 Windows多线程函数对应表
Linux Pthread API Windows SDK 库对应 API 创建 pthread_create CreateThread 退出 pthread_exit ThreadExit 等待 p ...