当前位置:网站首页>[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
边栏推荐
- Unity FAQ (I) lack of references
- 知识点滴 - PCB制造工艺流程
- 行測-圖形推理-4-字母類
- Sword finger offer 63 Maximum profit of stock
- Debezium series: binlogreader for source code reading
- 0-5vac to 4-20mA AC current isolated transmitter / conversion module
- Debezium series: source code reading snapshot reader
- Apple further entered the financial sector through the 'virtual card' security function in IOS 16
- LeetCode144. Preorder traversal of binary tree
- 行测-图形推理-2-黑白格类
猜你喜欢

行测-图形推理-2-黑白格类

Knowledge drop - PCB manufacturing process flow

Interview questions: how to test app performance?

PCL .vtk文件与.pcd的相互转换

数字化转型:五个步骤推动企业进步

详解全志V853上的ARM A7和RISC-V E907之间的通信方式

今日创见|企业促进创新的5大关键要素
![Leetcode interview question 02.07 Linked list intersection [double pointer]](/img/a5/58b4735cd0e47f1417ac151a1bcca4.jpg)
Leetcode interview question 02.07 Linked list intersection [double pointer]

What does the model number of asemi rectifier bridge kbpc1510 represent

PHP method of obtaining image information
随机推荐
Unity与WebGL的相爱相杀
De la famille debezium: SET ROLE statements supportant mysql8
Time convolution Network + soft threshold + attention mechanism to realize residual life prediction of mechanical equipment
Leetcode206. Reverse linked list
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
Apple further entered the financial sector through the 'virtual card' security function in IOS 16
Debezium系列之:引入对 LATERAL 运算符的支持
Two minutes, talk about some wrong understandings of MySQL index
Redis official ORM framework is more elegant than redistemplate
Debezium series: set role statement supporting mysql8
双非大厂测试员亲述:对测试员来说,学历重要吗?
Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
软件测评中心▏自动化测试有哪些基本流程和注意事项?
C development -- WPF simple animation
Personal statement of testers from Shuangfei large factory: is education important for testers?
Robot autonomous exploration series papers environment code
开发那些事儿:Go加C.free释放内存,编译报错是什么原因?
Software evaluation center ▏ what are the basic processes and precautions for automated testing?
Microbial health network, how to restore microbial communities
微服务架构开源框架详情介绍