package test;
import java.util.HashSet;
import java.util.Set;
public class Main {
public static int maxLength(String str){
if(str==null||str.equals("")){
return 0;
}
Set<Character> set=new HashSet<Character>();
int maxLength=0;
int pre=0;
int after=0;
while(after<str.length()){
if(!set.contains(str.charAt(after))){
set.add(str.charAt(after));
after++;
}else{
set.clear();
if((after-pre)>maxLength){
maxLength=after-pre;
}
pre++;
after=pre;
}
}
if((after-pre)>maxLength){
maxLength=after-pre;
}
return maxLength;
}
public static void main(String[] args) {
String str="y father was a self-taught mandolin player. He was one of the best string instrument players in our town. He could not read music, but if he heard a tune a few times, he could play it. When he was younger, he was a member of a small country music band. They would play at local dances and on a few occasions would play for the local radio station. He often told us how he had auditioned and earned a position in a band that featured Patsy Cline as their lead singer. He told the family that after he was hired he never went back. Dad was a very religious man. He stated that there was a lot of drinking and cursing the day of his audition and he did not want to be around that type of environment.";
System.out.println(maxLength(str));
}
}
光宇游戏Java开发(运营)笔试题.zip
版权申诉
156 浏览量
2023-07-19
09:57:44
上传
评论
收藏 3KB ZIP 举报
白话机器学习
- 粉丝: 8179
- 资源: 7687