当前位置:网站首页>Long substring without repeating characters for leetcode topic resolution
Long substring without repeating characters for leetcode topic resolution
2022-06-23 06:17:00 【ruochen】
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
public int lengthOfLongestSubstring(String s) {
if (s == null) {
return 0;
}
if (s.length() == 0 || s.length() == 1) {
return s.length();
}
char[] c = s.toCharArray();
int barrier = 0;
int maxLen = 1;
for (int i = 1; i < c.length; i++) {
for (int j = i - 1; j >= barrier; j--) {
if (c[i] == c[j]) {
barrier = j + 1;
break;
}
}
maxLen = Math.max(maxLen, i - barrier + 1);
}
return maxLen;
}边栏推荐
- jvm-06.垃圾回收器
- Wechat tried out the 1065 working system, and was forced to leave work at 18:00; It is said that Apple will no longer develop off screen fingerprint identification; Amd chief independent GPU architect
- 关于安装pip3 install chatterbot报错的问题
- pyinstaller 打包exe设置图标不显示
- Introduction to JVM principle
- Work accumulation - judge whether GPS is on
- Explicability of counter attack based on optimal transmission theory
- Sorting out common problems after crawler deployment
- mongodb 4.x绑定多个ip启动报错
- Gplearn appears assignment destination is read only
猜你喜欢
随机推荐
论文笔记: 多标签学习 LSML
基于T5L1的小型PLC设计方案
Pat class B 1026 program running time
【开源项目】excel导出lua配置表工具
Pat class B 1025 reverse linked list
Cryptography series: certificate format representation of PKI X.509
Kotlin interface
Summary of ant usage (I): using ant to automatically package apk
The official artifact of station B has cracked itself!
Vant web app calendar component performance optimization calendar add min date the minimum date page loads slowly
Global attribute lang attribute
jvm-04. Object's memory layout
【Cocos2d-x】截图分享功能
求二叉树最宽的层有多少个节点
[cocos2d-x] erasable layer:erasablelayer
mysql以逗号分隔的字段作为查询条件怎么查——find_in_set()函数
jvm-01. Instruction rearrangement
Pat class B 1014 C language
如何指定pig-register项目日志的输出路径
(1) Basic learning - Common shortcut commands of vim editor






![[cocos2d-x] screenshot sharing function](/img/fc/e3d7e5ba164638e2c48bc4a52a7f13.png)


![[cocos2d-x] erasable layer:erasablelayer](/img/6e/1ee750854dfbe6a0260ca12a4a5680.png)