最長重複文字列なし
1420 ワード
import java.util.HashSet;
/**
*
* Created by 76549 on 2019-05-15.
*/
public class LongStr {
/**
*
* @param s
* @return
*/
public static String longNonRecurString(String s) {
int begin=0;
int ans=0;
for (int i = 0; i < s.length(); i++) {
for (int j = i+1; j < s.length(); j++) {
String subs=s.substring(i,j);
if(isNoRecurstr(subs)){
if(j-i>ans){
ans=j-i;
begin=i;
}
ans=Math.max(ans,j-i);
}
}
}
return s.substring(begin,begin+ans);
}
/**
*
* @param str
* @return
*/
public static boolean isNoRecurstr(String str){
HashSet h=new HashSet();
for(int i=0;i h=new HashSet();
while(i