solution:
public int lengthOfLongestSubstring(String s) {
int maxCount = 0;
for(int i = 0; i < s.length(); i++) {
Set<Character> previous = new HashSet<Character>();
int count = 0;
for(int j = i; j < s.length(); j++) {
if(previous.add(s.charAt(j))) {
count++;
}
else {
break;
}
}
maxCount = Math.max(maxCount, count);
}
return maxCount;
}
No comments:
Post a Comment