当前位置:网站首页>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;
}边栏推荐
- [DaVinci developer topic] -41-app how SWC reads and writes NVM block data
- Tencent security 2021 report white paper collection (download attached)
- jvm-06. Garbage collector
- Pat class B 1009 C language
- Alibaba cloud ack one and ACK cloud native AI suite have been newly released to meet the needs of the end of the computing era
- 给定二叉树的某个节点,返回该节点的后继节点
- Pyinstaller packaging pyttsx3 error
- How to specify the output path of pig register Project Log
- Activity startup mode and life cycle measurement results
- Visual Studio调试技巧
猜你喜欢

Adnroid activity screenshot save display to album view display picture animation disappear

Summary of ant usage (I): using ant to automatically package apk

jvm-03. JVM memory model

微软面试题:打印折纸的折痕

Visual studio debugging tips

Efficient office of fintech (I): automatic generation of trust plan specification

如何指定pig-register项目日志的输出路径
![[cocos2d-x] custom ring menu](/img/fd/c18c39ae738f6c1d2b76b6c54dc654.png)
[cocos2d-x] custom ring menu

jvm-03.jvm内存模型

内存分析与内存泄漏检测
随机推荐
Learning Tai Chi Maker - esp8226 (11) distribution network with WiFi manager Library
Wireshark TS | 视频 APP 无法播放问题
jvm-06.垃圾回收器
Introduction to JVM principle
Causes and methods of exe flash back
JS interview question - anti shake function
Visual studio debugging tips
100-300 cases of single chip microcomputer program (detailed explanation of notes)
Pyinstaller packaging pyttsx3 error
Redis 哨兵
mysql以逗号分隔的字段作为查询条件怎么查——find_in_set()函数
gplearn出现 assignment destination is read-only
Pat class B 1022 d-ary a+b
Kotlin collaboration +retro most elegant network request use
Cryptography series: certificate format representation of PKI X.509
Summary of ant usage (I): using ant to automatically package apk
[DaVinci developer topic] -42- how to generate template and header files of APP SWC
Global attribute lang attribute
Leetcode topic resolution divide two integers
给定二叉树的某个节点,返回该节点的后继节点