当前位置:网站首页>[record of question brushing] 3 Longest substring without duplicate characters
[record of question brushing] 3 Longest substring without duplicate characters
2022-07-07 23:00:00 【InfoQ】
One 、 Title Description
- 0 <= s.length <= 5 * 104
- s By the English letters 、 Numbers 、 Symbols and spaces
Two 、 Thought analysis
- Define a record starting start And at the end of a record end For example 1 MediumabcThis window (start=0,end=3) It meets the requirements of the topic
- When the window continues to expand toabcawhen , Will not be satisfied , We can only let someone move start(start+n), Until there is no repetition , The example changes tobca.
- Keep recording the length of the window during the window scanning (end-start), Update to the largest during the move . It is the final answer we need
- At the same time, in order to quickly determine whether there are duplicate values and value positions in the acquisition window We can use a hash table to record values and positions .
3、 ... and 、 Code implementation
class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<Character,Integer> map = new HashMap<>();
// Records of the results That is, the maximum length of the window
int resultMax = 0;
// The first left and right boundaries of the window
int start = 0;
int end = 0;
for ( end = 0; end < s.length() ; end ++) {
if (map.containsKey(s.charAt(end))){
// When there are duplicate values in the window Move the left border of the window start
start = Math.max(start,map.get(s.charAt(end)) + 1);
}
map.put(s.charAt(end),end);
resultMax = Math.max(resultMax,end - start + 1 );
}
return resultMax;
}
}

summary
边栏推荐
- Leetcode206. Reverse linked list
- Transparent i/o model from beginning to end
- How pyGame rotates pictures
- LeetCode707. Design linked list
- Debezium系列之:支持 mysql8 的 set role 語句
- Robot autonomous exploration DSVP: code parsing
- Interview questions: how to test app performance?
- PCL . VTK files and Mutual conversion of PCD
- 【测试面试题】页面很卡的原因分析及解决方案
- Debezium系列之: 支持在 KILL 命令中使用变量
猜你喜欢
Microbial health network, how to restore microbial communities
Line test - graphic reasoning -7- different graphic classes
php 获取图片信息的方法
Unity与WebGL的相爱相杀
LeetCode206. Reverse linked list [double pointer and recursion]
Sword finger offer 55 - I. depth of binary tree
IP network active evaluation system -- x-vision
微生物健康网,如何恢复微生物群落
开发那些事儿:Go加C.free释放内存,编译报错是什么原因?
GBU1510-ASEMI电源专用15A整流桥GBU1510
随机推荐
Gazebo import the mapping model created by blender
XMIND mind mapping software sharing
行测-图形推理-7-相异图形类
Leetcode94. Middle order traversal of binary trees
苹果在iOS 16中通过'虚拟卡'安全功能进一步进军金融领域
新版代挂网站PHP源码+去除授权/支持燃鹅代抽
How pyGame rotates pictures
LeetCode144. Preorder traversal of binary tree
Leetcode19. Delete the penultimate node of the linked list [double pointer]
行测-图形推理-5-一笔画类
Amesim2016 and matlab2017b joint simulation environment construction
De la famille debezium: SET ROLE statements supportant mysql8
Line test graph reasoning graph group class
Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
QT graphicsview graphical view usage summary with flow chart development case prototype
Some parameters of Haikang IPC
Loki, the "open source star picking program", realizes the efficient management of harbor logs
IP network active evaluation system -- x-vision
Line test - graphic reasoning - 1 - Chinese character class
Line test - graphic reasoning - 3 - symmetric graphic class