寻找一串字符中,最长不重复的子串的长度

就当做个笔记,主要用到了Hashset方法中add不能添加重复字段的属性,

再用.size得到长度

package com.test;

import java.util.HashSet;
import java.util.Scanner;

public class Test2 {

    public void length(){
        Scanner in=new Scanner(System.in);
        String s=in.next();
        char c[]=s.toCharArray();
        int i;
        int count;
        int len=s.length();
        HashSet<String> set = new HashSet<String>();

        for(i=0;i<len;i++){
            set.add(String.valueOf(c[i]));
        }

        count=set.size();
        System.out.println(count);
    }
    public static void main(String args[]){
        Test2 ts=new Test2();
        ts.length();
    }
}

Hashset的具体介绍(52条消息) HashSet_Carryi的博客-CSDN博客寻找一串字符中,最长不重复的子串的长度https://blog.csdn.net/Carryi/article/details/120294032?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164126132316780265429629%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164126132316780265429629&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-3-120294032.first_rank_v2_pc_rank_v29&utm_term=%E6%80%8E%E4%B9%88%E5%BE%97%E5%88%B0hashset%E7%9A%84%E9%95%BF%E5%BA%A6&spm=1018.2226.3001.4187

上一篇:【重拾算法】并查集


下一篇:11.FastAPI模型与字典