I think my logic is good but I suppose something I don't see is wrong
package com.codegym.task.task39.task3901;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
Unique substrings
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter your string: ");
String s = bufferedReader.readLine();
System.out.println("The longest unique substring length is: \n" + lengthOfLongestUniqueSubstring(s));
}
public static int lengthOfLongestUniqueSubstring(String s) {
if (s == null || s.isEmpty())
return 0;
Set<Character> charsSet = new LinkedHashSet<>();
char[] charsArr = s.toCharArray();
int longestLength = 0;
int next = 0;
for (int i = 0; i < charsArr.length; i++) {
if (charsSet.add(charsArr[i]) == false) {
if (longestLength < charsSet.size()) {
longestLength = charsSet.size();
}
charsSet.clear();
i = ++next;
}
}
return longestLength;
}
}