feat: 2025-10-23打卡

This commit is contained in:
wu xiangkai
2025-10-23 16:32:13 +08:00
parent 59f245dda7
commit f06095ad7e
9 changed files with 378 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
/*
* @lc app=leetcode id=3 lang=java
*
* [3] Longest Substring Without Repeating Characters
*/
// @lc code=start
class Solution {
public int lengthOfLongestSubstring(String s) {
if(s.length() == 0) {
return 0;
}
Set<Character> chs = new HashSet<>();
int i = 0, j = 0, r = 0, cur = 0;
while(j < s.length()) {
if(!chs.contains(s.charAt(j))) {
chs.add(s.charAt(j));
cur++;
if(cur > r) {
r = cur;
}
} else {
while(s.charAt(i) != s.charAt(j)) {
chs.remove(s.charAt(i));
i++;
}
i++;
cur = j - i + 1;
if(cur > r) {
r = cur;
}
}
j++;
}
return r;
}
}
// @lc code=end