当前位置:网站首页>3. 无重复字符的最长子串
3. 无重复字符的最长子串
2022-08-03 05:09:00 【破烂摆烂人】
3. 无重复字符的最长子串

方法一:滑动窗口


public int lengthOfLongestSubstring(String s) {
Set<Character> set = new HashSet<Character>();/*哈希集合-记录字符是否重复*/
int len = s.length();/*数组长度*/
int ans = 0;/*记录最大长度*/
int right = 0;/*右指针*/
int left = 0;/*左指针*/
while (left<len){
while (right < len && !set.contains(s.charAt(right))) {
/*右指针右移条件*/
set.add(s.charAt(right));
right++;
}
ans = Math.max(ans, right-left);/*更新最大长度*/
set.remove(s.charAt(left++));/*集合移除最左的元素-左指针右移*/
}
return ans;
}

方法二:滑动窗口及优化


边栏推荐
- Shell之条件语句
- Tributyl-mercaptophosphane "tBuBrettPhos Pd(allyl)" OTf), 1798782-17-8
- 「短视频+社交电商」营销模式爆发式发展,带来的好处有什么?
- Technology Sharing | How to do assertion verification for xml format in interface automation testing?
- 【生物素叠氮化物|cas:908007-17-0】价格_厂家
- 【开发者必看】【push kit】推送服务服务典型问题合集2
- js的垃圾回收机制
- DFS's complement to pruning
- 7.Keras开发简介
- 设计模式——组合模式、享元模式(Integer缓存)(结构型模式)
猜你喜欢

How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use

unity2D横板游戏教程6-敌人AI以及受击动画

Alienware上线首个数字时装AR试穿体验

【Harmony OS】【ArkUI】ets开发 基础页面布局与数据连接

Jmeter 模拟多用户登录的两种方法

13.< tag-动态规划和回文字串>lt.647. 回文子串 + lt.516.最长回文子序列

打破传统电商格局,新型社交电商到底有什么优点?

常见荧光染料修饰多种基团及其激发和发射波长数据一览数据

Concepts and Methods of Exploratory Testing

2022/08/02 Study Notes (day22) Multithreading
随机推荐
typescript39-class类的可见修饰符
Get the Ip tool class
OSI的分层特点、传输过程与三次握手、四次挥手、tcp与udp包头的描述
WebSocket的实际应用
刚上线就狂吸70W粉,新型商业模式“分享购”来了,你知道吗?
Interface testing framework of actual combat (2) | interface request assertion
4.深度学习的几何解释与梯度的优化
Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
用户密码加密工具
【Harmony OS】【FAQ】鸿蒙问题合集1
如何利用 Flutter 实现炫酷的 3D 卡片和帅气的 360° 展示效果
Peptides mediated PEG DSPE of phospholipids, targeted functional materials - PEG - RGD/TAT/NGR/APRPG
安装IIS服务(Internet信息服务(Internet Information Services,简写IIS,互联网信息服务)
MCM箱模型建模方法及大气O3来源解析
Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
MySQL 出现 The table is full 的解决方法
typescript44-对象之间的类兼容器
设计模式——组合模式、享元模式(Integer缓存)(结构型模式)
UV 裂解的生物素-PEG2-叠氮|CAS:1192802-98-4生物素接头