3. 无重复字符的最长子串

简介: 3. 无重复字符的最长子串

image.png


方法一:hashSet


class Solution {
    public int lengthOfLongestSubstring(String s) {
        if(s==null||s.length()==0){
            return 0;
        }
        Set<Character> set=new HashSet<>();
        int max=0;
        int current=0;
        for(int i=0;i<s.lenght();i++){
            while(current<=i&&!set.containsKey(s.charAt(i))){
                set.
                current++;
            }
        }
    }
}
目录
相关文章
|
8天前
|
存储
【字符串】最长不含重复字符的子字符串
【字符串】最长不含重复字符的子字符串
|
8月前
|
索引
LeetCode3-无重复字符的最长子串
LeetCode3-无重复字符的最长子串
|
2天前
|
并行计算
求无重复字符的最长子串
求无重复字符的最长子串
|
8天前
|
存储 算法 Go
LeetCode 第三题: 无重复字符的最长子串
  给定一个字符串,请你找出其中不含有重复字符的最长子串的长度。
|
8天前
leetcode:3. 无重复字符的最长子串
leetcode:3. 无重复字符的最长子串
17 0
|
8天前
3. 无重复字符的最长子串
3. 无重复字符的最长子串
23 0
|
8天前
leetcode-3:无重复字符的最长子串
leetcode-3:无重复字符的最长子串
22 0
|
8天前
|
存储 算法 JavaScript
Leetcode算法系列| 3. 无重复字符的最长子串
Leetcode算法系列| 3. 无重复字符的最长子串
|
8月前
无重复字符的最长子串
写一个if语句,当left小于right的时候,就写一个循环遍历从left下标开始的元素到right下标前面的元素,判断是否与right下标的元素相同,相同的话就跳出循环,令left 等于 与 right下标元素相同的元素后面的元素.怎么判断在left和right之间是否存在又和right相同的元素呢?这就用到了falg.如果left < right 的时候就让 right++; max = max = right - left + 1。
33 0
|
11月前
|
算法 Java Python
leetcode:3.无重复字符的最长子串
首先最容易想到的就是暴力解法,列出所有的子字符串,然后逐个检查是否包含重复的字符就行了,这样思路很简单,但是效率太慢,不推荐。
37 0